Hello everybody!
I'm building a robot that will avoid obstacles while being set to different "moods" trough an IR sensor and a remote. Let's say by pressing key "1", it's behavoir will be agressive, by pressing "2", it's behavoir will be happy and so on to up to 10 behavoirs.
My pseudocode is like this:
press 1 -> agresive;
press 2 -> happy;
.
.
.
press 10 -> share love to everybody;
I could make it up to the point where i see in serial monitor the key that i press. Let's say I press 1: it becomes agressive but i couldn't manage to change it to the happy "mood". At this point it is stuck on the first mode that i press.
Here is my code:
#include <LedControl.h>
#include <IRremote.h>
int DIN = 13;
int CS = 10;
int CLK = 9;
int PWM_A = 5;
int PWM_B = 6;
int FW_A = 4;
int FW_B = 8;
int BW_A = 7;
int BW_B = 12;
int S_st = 0;
int S_dr = 0;
int receiver = 11;
int mode = 0;
uint32_t duration; // duration of the round trip
uint32_t cm; // distance of the obstacle
const uint8_t trigPin = 3;
const uint8_t echoPin = 2;
byte smile[8]= {0xFF,0x81,0xA5,0x81,0xA5,0xBD,0x81,0xFF};
byte fata[8]= {0x3C,0x3C,0x3C,0xFF,0xFF,0x7E,0x3C,0x18};
byte spate[8]= {0x18,0x3C,0x7E,0xFF,0xFF,0x3C,0x3C,0x3C};
byte st[8]= {0x18,0x1C,0xFE,0xFF,0xFF,0xFE,0x1C,0x18};
byte dr[8]= {0x18,0x38,0x7F,0xFF,0xFF,0x7F,0x38,0x18};
byte OFF[8]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
LedControl lc=LedControl(DIN,CLK,CS,0);
IRrecv irrecv(receiver);
decode_results results;
void oprire(){
printByte(OFF);
digitalWrite(FW_A,LOW);
digitalWrite(FW_B,LOW);
digitalWrite(BW_A,LOW);
digitalWrite(BW_B,LOW);
analogWrite(PWM_A,0);
analogWrite(PWM_B,0);
}
void inainte(){
printByte(fata);
digitalWrite(FW_A,HIGH);
digitalWrite(BW_A,LOW);
analogWrite(PWM_A,73);
digitalWrite(FW_B,HIGH);
digitalWrite(BW_B,LOW);
analogWrite(PWM_B,80);
}
void inainteIncet(){
printByte(fata);
digitalWrite(FW_A,HIGH);
digitalWrite(BW_A,LOW);
analogWrite(PWM_A,70);
digitalWrite(FW_B,HIGH);
digitalWrite(BW_B,LOW);
analogWrite(PWM_B,77);
}
void inapoi(){
printByte(spate);
digitalWrite(FW_A,LOW);
digitalWrite(BW_A,HIGH);
analogWrite(PWM_A,73);
digitalWrite(FW_B,LOW);
digitalWrite(BW_B,HIGH);
analogWrite(PWM_B,80);
}
void stanga(){
printByte(st);
digitalWrite(FW_A,LOW);
digitalWrite(BW_A,HIGH);
analogWrite(PWM_A,70);
digitalWrite(FW_B,HIGH);
digitalWrite(BW_B,LOW);
analogWrite(PWM_B,70);
}
void dreapta(){
printByte(dr);
digitalWrite(FW_A,HIGH);
digitalWrite(BW_A,LOW);
analogWrite(PWM_A,100);
digitalWrite(FW_B,LOW);
digitalWrite(BW_B,HIGH);
analogWrite(PWM_B,100);
}
void printByte(byte character []){
int i = 0;
for(i=0;i<8;i++)
{lc.setRow(0,i,character[i]);}
}
void setup() {
lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup
lc.setIntensity(0,15); // Set the brightness to maximum value
lc.clearDisplay(0); // and clear the
pinMode(PWM_A, OUTPUT);
pinMode(PWM_B, OUTPUT);
pinMode(FW_A, OUTPUT);
pinMode(FW_B, OUTPUT);
pinMode(BW_A, OUTPUT);
pinMode(BW_B, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(300);
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) // have we received an IR signal?
{
if (results.value == 0xFF6897){
mode = 0;
Serial.println("0");
}
else if (results.value == 0xFF30CF){
mode = 1;
while(mode == 1){
Serial.println("whilee1");
}
}
Serial.println("1");
}
else if (results.value == 0xFF18E7){
mode = 2;
while(mode == 2){
Serial.println("whilee2");
}
}
Serial.println("2");
}
else if (results.value == 0xFF7A85){
mode = 3;
Serial.println("3");
}
else if (results.value == 0xFF10EF){
mode = 4;
Serial.println("4");
}
else if (results.value == 0xFF38C7){
mode = 5;
Serial.println("5");
}
else if (results.value == 0xFF5AA5){
mode = 6;
Serial.println("6");
}
else if (results.value == 0xFF42BD){
mode = 7;
Serial.println("7");
}
else if (results.value == 0xFF4AB5){
mode = 8;
Serial.println("8");
}
else if (results.value == 0xFF52AD){
mode = 9;
Serial.println("9");
}
delay(200);
irrecv.resume(); // receive the next value
}
}
//0 oprire
//1 sincron
//2 cearta
//3 alintat
//4 mila/frica
//5 dans/sincron agitat
//6 dusmanie/dragoste
//7 sa comunice cu profu DA / NU / Asa si asa / DAAAAA
//8 cald
//9 spontan
// digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000);
// digitalWrite(trigPin, LOW);
// duration = pulseIn(echoPin, HIGH);
// cm = (uint32_t)((duration<<4)+duration)/1000.0;
Please help me guys, i need to use this robot Friday on a public debate.