Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include <Arduino.h> //arduino lib
#include <Wire.h> //Not My code
#include <SoftwareSerial.h> //Not My code
#include <MeAuriga.h> //library for the module that i was using
MeEncoderOnBoard Encoder_1(SLOT1); //Not My Code
MeEncoderOnBoard Encoder_2(SLOT2); //Not My Code
void _delay(float seconds){ //Not My Code
long endTime = millis() + seconds * 1000; //Not My Code
while(millis() < endTime)_loop(); //Not My Code
}
void _loop(){ //Not My Code
Encoder_1.loop(); //Not My Code
Encoder_2.loop(); //Not My Code
}
void isr_process_encoder1(void) //Not My Code
{
if(digitalRead(Encoder_1.getPortB()) == 0){ //Not My Code
Encoder_1.pulsePosMinus(); //Not My Code
}else{ //Not My Code
Encoder_1.pulsePosPlus(); //Not My Code
}
}
void isr_process_encoder2(void) //Not My Code
{
if(digitalRead(Encoder_2.getPortB()) == 0){ //Not My Code
Encoder_2.pulsePosMinus(); //Not My Code
}else{ //Not My Code
Encoder_2.pulsePosPlus(); //Not My Code
}
}
void move(int direction, int speed) //Not My Code
{ //Not My Code
int leftSpeed = 0; //Not My Code
int rightSpeed = 0; //Not My Code
if(direction == 1){ //Not My Code
leftSpeed = -speed; //Not My Code
rightSpeed = speed; //Not My Code
}else if(direction == 2){ //Not My Code
leftSpeed = speed; //Not My Code
rightSpeed = -speed; //Not My Code
}else if(direction == 3){ //Not My Code
leftSpeed = -speed; //Not My Code
rightSpeed = -speed; //Not My Code
}else if(direction == 4){ //Not My Code
leftSpeed = speed; //Not My Code
rightSpeed = speed; //Not My Code
}
Encoder_1.setTarPWM(leftSpeed); //Not My Code
Encoder_2.setTarPWM(rightSpeed); //Not My Code
}
void moveDegrees(int direction,long degrees, int speed_temp) //Not My Code
{
speed_temp = abs(speed_temp); //Not My Code
if(direction == 1) //Not My Code
{
Encoder_1.move(-degrees,(float)speed_temp); //Not My Code
Encoder_2.move(degrees,(float)speed_temp); //Not My Code
}
else if(direction == 2) //Not My Code
{
Encoder_1.move(degrees,(float)speed_temp); //Not My Code
Encoder_2.move(-degrees,(float)speed_temp); //Not My Code
}
else if(direction == 3) //Not My Code
{
Encoder_1.move(-degrees,(float)speed_temp); //Not My Code
Encoder_2.move(-degrees,(float)speed_temp); //Not My Code
}
else if(direction == 4) //Not My Code
{
Encoder_1.move(degrees,(float)speed_temp); //Not My Code
Encoder_2.move(degrees,(float)speed_temp); //Not My Code
}
}
double SoundDiff; //create a float varibale to store sound diffrence
MeSoundSensor soundsensor_14(14); //Not My Code
double angle_rad = PI/180.0; //Not My Code
double angle_deg = 180.0/PI; //Not My Code
double brightness; //create a float varibale to store brightness value
double speed; //Not My Code
double distance; //create a float varibale to store distance value
MeLightSensor lightsensor_12(12); //Not My Code
MeUltrasonicSensor ultrasonic_10(10); //Not My Code
MeRGBLed rgbled_0(0, 12); //Not My Code
MeBuzzer buzzer; //Not My Code
void setup(){
TCCR1A = _BV(WGM10); //Not My Code
TCCR1B = _BV(CS11) | _BV(WGM12); //Not My Code
TCCR2A = _BV(WGM21) | _BV(WGM20); //Not My Code
TCCR2B = _BV(CS21); //Not My Code
attachInterrupt(Encoder_1.getIntNum(), isr_process_encoder1, RISING); //Not My Code
attachInterrupt(Encoder_2.getIntNum(), isr_process_encoder2, RISING); //Not My Code
rgbled_0.setpin(44); //Not My Code
buzzer.setpin(45); //Not My Code
_delay(3); // a delay to make sure the bot doesnt start moving right after activat
int timer = 300; // creates an interger called timer and sets it to 300
brightness = lightsensor_12.read(); // reads the the current brightness level
int bright2=lightsensor_12.read(); //creates a new interger and reads the the current brightness level
while(!((brightness) < (bright2 - 50))) // tests if the bot entered a darker place
{ // if it hasnt found a darker place,the bot will continue to move around and scan the room
move(1,75);
_delay(0.1);
brightness = lightsensor_12.read();
distance = ultrasonic_10.distanceCm(); // reads the distance to the object infront of it
if((distance) < (30)){ // tests if something is infront of it,if there is, the bot avoids the object
move(2,75);
_delay(0.5);
move(3,75);
_delay(0.7);
}
timer--; //every loop the timer is reduces by one
if (timer==0)bright2=10000;
}
rgbled_0.setColor(0,255,0,0); //bot lights change color to
rgbled_0.show();
move(1,0); //bot stops moving
_delay(0.1);
}
void loop(){
double sound=500; //create a float varibale to store sound and sets it 500
double soundness=0; //create a float varibale to store current sound
while(!(sound<soundness)) //loops while the set sound is bigger than the sound suround it
{
soundness=soundsensor_14.strength(); //records the curent volume level
rgbled_0.setColor(0,0,0,255); //changes the color
rgbled_0.show();
_delay(0.3);
buzzer.tone(950, 600); //plays a tone
delay(20);
soundness=soundsensor_14.strength(); //resets the volume level
rgbled_0.setColor(0,255,255,255); // cahnges the colour
rgbled_0.show();
_delay(0.3);
buzzer.tone(700, 400); //plays a note
delay(20);
}
rgbled_0.setColor(0,0,255,0); // cahnges the colour
rgbled_0.show();
_delay(3);
_loop(); //loops everything
}