I don't understand why so many errors
forum_3:-1: error: expected unqualified-id before numeric constant
forum_3:2: error: 'VOID' does not name a type
forum_3:3: error: 'CONST' does not name a type
forum_3:4: error: 'CONST' does not name a type
forum_3:5: error: 'CONST' does not name a type
forum_3:6: error: 'CONST' does not name a type
forum_3:7: error: 'CONST' does not name a type
forum_3:8: error: 'CONST' does not name a type
forum_3:9: error: 'CONST' does not name a type
forum_3:10: error: 'CONST' does not name a type
forum_3:11: error: 'CONST' does not name a type
forum_3:25: error: 'VOID' does not name a type
Thanks for all the replies
CODE
// These constants won't change:
CONST INT ANALOGPIN = 0; // pin that the sensor is attached to
CONST INT LEDPIN1 = 2; // pin that the LED is attached to yellow
CONST INT LEDPIN2 = 3; // pin that the LED is attached to green
CONST INT LEDPIN3 = 4; // pin that the LED is attached to blue
CONST INT LEDPIN4 = 5; // red
CONST INT THRESHOLD1 = 15; // yellow led
CONST INT THRESHOLD2 = 25; // green led
CONST INT THRESHOLD3 = 50; // blue led
CONST INT THRESHOLD4 = 75 // red led
void setup() {
// initialize the LED pinS as an output:
PINMODE ledPin1, (OUTPUT); // yellow
PINMODE ledpin2,(OUTPUT); //green
PINMODE ledPin3, (OUTPUT); //blue
PINMODE ledPin4, (OUTPUT); //red
// initialize serial communications:
SERIAL.BEGIN(9600);
}
VOID LOOP() {
// read the value of the potentiometer:
INT ANALOGVALUE = ANALOGREAD(ANALOGPIN);
IF (ANALOGVALUE > THRESHOLD1) // yellow
DIGITALWRITE(LEDPIN1, HIGH);
ELSE
DIGITALWRITE(LEDPIN1,LOW);
IF (ANALOGVALUE > THRESHOLD2) //green
DIGITALWRITE(LEDPIN2, HIGH);
ELSE
DIGITALWRITE(LEDPIN2,LOW);
IF (ANALOGVALUE > THRESHOLD3) //blue
DIGITALWRITE (LEDPIN3, HIGH);
ELSE
DIGITALWRITE(LEDPIN3,LOW);
IF (ANALOGVALUE > THRESHOLD4) // red
DIGITALWRITE(LEDPIN4, HIGH);
ELSE
DIGITALWRITE(LEDPIN4, LOW);
// print the analog value:
SERIAL.PRINTLN(ANALOGVALUE);
delay(10); // delay in between reads for stability
}
Th'ere a few things wrong with that code - firstly, C++ is case sensitive, hence the high number of errors due to everything being in capital letters (almost everything).
There were a few syntax erros in the pinMode calls too, and missing semi colons etc here and there.
This compiles for me - hopefully it will for you too.
Hope that helps.
const int ANALOGPIN = 0; // pin that the sensor is attached to
const int LEDPIN1 = 2; // pin that the LED is attached to yellow
const int LEDPIN2 = 3; // pin that the LED is attached to green
const int LEDPIN3 = 4; // pin that the LED is attached to blue
const int LEDPIN4 = 5; // red
const int THRESHOLD1 = 15; // yellow led
const int THRESHOLD2 = 25; // green led
const int THRESHOLD3 = 50; // blue led
const int THRESHOLD4 = 75; // red led
void setup() {
// initialize the LED pinS as an output:
pinMode (LEDPIN1, OUTPUT); // yellow
pinMode (LEDPIN2, OUTPUT); //green
pinMode (LEDPIN3, OUTPUT); //blue
pinMode (LEDPIN4, OUTPUT); //red
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the potentiometer:
int ANALOGVALUE = analogRead(ANALOGPIN);
if (ANALOGVALUE > THRESHOLD1) // yellow
digitalWrite(LEDPIN1, HIGH);
else
digitalWrite(LEDPIN1,LOW);
if (ANALOGVALUE > THRESHOLD2) //green
digitalWrite(LEDPIN2, HIGH);
else
digitalWrite(LEDPIN2,LOW);
if (ANALOGVALUE > THRESHOLD3) //blue
digitalWrite(LEDPIN3, HIGH);
else
digitalWrite(LEDPIN3,LOW);
if (ANALOGVALUE > THRESHOLD4) // red
digitalWrite(LEDPIN4, HIGH);
else
digitalWrite(LEDPIN4, LOW);
// print the analog value:
Serial.println(ANALOGVALUE);
delay(10); // delay in between reads for stability
}