I have some code and I don't know what is wrong with it.
int ir_pin = 2; //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 13; // built in LED
int ledLEFT = 12;
int ledFORWARD = 11;
int ledBACK = 10;
int ledRIGHT = 8;
int debug = 1;
int start_bit = 2000;
int bin_1 = 1000;
int bin_0 = 400;
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(ir_pin, INPUT);
pinMode(ledLEFT, OUTPUT);
pinMode(ledFORWARD, OUTPUT);
pinMode(ledBACK, OUTPUT);
pinMode(ledRIGHT, OUTPUT);
digitalWrite(led_pin, LOW);
Serial.begin(9600);
}
void loop()
{
int key = getIRKey();
if (key != -1)
{
Serial.print("Key Received: ");
Serial.println(key);
}
switch (key)
{
case 16: // left + forward
LF();
break;
//case xxxx: // forward
// F();
// break;
case 1040: // right + forward
RF();
break;
case 2064: // left + back
LB();
break;
case 528: // back
B();
break;
//case xxxx: // right + back
RB();
break;
//case xxxx: // stop
// S();
// break;
case -1: // no key received
break;
}
}
void LF() //To go left + forward.
{
digitalWrite(ledLEFT, HIGH);
digitalWrite(ledFORWARD, HIGH);
digitalWrite(ledBACK, LOW);
digitalWrite(ledRIGHT, LOW);
delay(100);
digitalWrite(ledFORWARD, LOW);
}
void F() //To go forward.
{
digitalWrite(ledLEFT, LOW);
digitalWrite(ledFORWARD, HIGH);
digitalWrite(ledBACK, LOW);
digitalWrite(ledRIGHT, LOW);
delay(100);
digitalWrite(ledFORWARD, LOW);
}
void RF() //To go right + forward.
{
digitalWrite(ledLEFT, LOW);
digitalWrite(ledFORWARD, HIGH);
digitalWrite(ledBACK, LOW);
digitalWrite(ledRIGHT, HIGH);
delay(100);
digitalWrite(ledFORWARD, LOW);
}
void LB() { //To go left + back.
digitalWrite(ledLEFT, HIGH);
digitalWrite(ledFORWARD, LOW);
digitalWrite(ledBACK, HIGH);
digitalWrite(ledRIGHT, LOW);
delay(100);
digitalWrite(ledBACK, LOW);
}
void B() { //To go back.
digitalWrite(ledLEFT, LOW);
digitalWrite(ledFORWARD, LOW);
digitalWrite(ledBACK, HIGH);
digitalWrite(ledRIGHT, LOW);
delay(100);
digitalWrite(ledBACK, LOW);
}
void RB() { //To go right + back.
digitalWrite(ledLEFT, LOW);
digitalWrite(ledFORWARD, LOW);
digitalWrite(ledBACK, HIGH);
digitalWrite(ledRIGHT, HIGH);
delay(100);
digitalWrite(ledBACK, LOW);
}
void S() { //To stop.
digitalWrite(ledLEFT, LOW);
digitalWrite(ledFORWARD, LOW);
digitalWrite(ledBACK, LOW);
digitalWrite(ledRIGHT, LOW);
delay(100);
}
void getIRKey() {
int data[12];
digitalWrite(led_pin, HIGH);
while(pulseIn(ir_pin, LOW) < 2200) {
}
data[0] = pulseIn(ir_pin, LOW);
data[1] = pulseIn(ir_pin, LOW);
data[2] = pulseIn(ir_pin, LOW);
data[3] = pulseIn(ir_pin, LOW);
data[4] = pulseIn(ir_pin, LOW);
data[5] = pulseIn(ir_pin, LOW);
data[6] = pulseIn(ir_pin, LOW);
data[7] = pulseIn(ir_pin, LOW);
data[8] = pulseIn(ir_pin, LOW);
data[9] = pulseIn(ir_pin, LOW);
data[10] = pulseIn(ir_pin, LOW);
data[11] = pulseIn(ir_pin, LOW);
digitalWrite(led_pin, LOW);
if (debug == 1) {
}
for (int i=0; i<=11; i++) {
if (debug == 1) {
}
if(data[i] > bin_1) {
data[i] = 1;
}
else {
if(data[i] > bin_0) {
data[i] = 0; }
else {
data[i] = 2;
}
}
}
for (int i = 0; i <= 11; i++)
{
if (data[i] > 1)
{
return -1;
}
}
int result = 0;
int seed = 1;
for(int i = 11; i >= 0; i--)
{
if(data[i] == 1)
{
result += seed;
}
seed = seed * 2;
}
return result;
}
Here are the errors:
Something1:-1: error: expected unqualified-id before 'reinterpret_cast'
Something1:-1: error: expected `)' before 'reinterpret_cast'
Something1:-1: error: expected unqualified-id before ')' token
Something1.cpp: In function 'void loop()':
Something1:30: error: void value not ignored as it ought to be
Something1.cpp: At global scope:
Something1:82: error: expected unqualified-id before 'reinterpret_cast'
Something1:82: error: expected `)' before 'reinterpret_cast'
Something1:82: error: expected unqualified-id before ')' token
Something1.cpp: In function 'void getIRKey()':
Something1:183: error: return-statement with a value, in function returning 'void'
Something1:197: error: return-statement with a value, in function returning 'void'