Offline
Newbie
Karma: 0
Posts: 6
|
 |
« on: August 27, 2012, 07:49:11 am » |
i've been having some issues with the arduino uno. i have written a code for it but the board keeps getting locked into a loop and running the alarm process regardless of what i do. also for some reason the output marked red goes high whenever i disconnect the proxy, that is if the alarm doesn't continue to sound. here is a sample of the code. i thought it might be the board but i have bought two and they both do the same thing. any suggestions?
const int Red = 7; const int Green = 4; const int Blue = 6; const int Yellow = 8; const int Proxy = A0; const int Redin = A1; const int Greenin = A2; const int Bluein = A3; const int Yellowin = A4; const int Alarm = 9; int pval = 0; //proxy value int rval = 0; //red value int gval = 0; //green value int bval = 0; //blue value int yval = 0; //yellow value
void setup() { pinMode(Red, OUTPUT); pinMode(Green, OUTPUT); pinMode(Blue, OUTPUT); pinMode(Yellow, OUTPUT); pinMode(Proxy, INPUT); pinMode(Alarm, OUTPUT); pinMode(Redin, INPUT); pinMode(Greenin, INPUT); pinMode(Bluein, INPUT); pinMode(Yellowin, INPUT); } void loop() { pval = analogRead(Proxy); //read proxy value and store it if (pval < 1000) { digitalWrite(Alarm, LOW); digitalWrite(Red, LOW); digitalWrite(Green, LOW); digitalWrite(Blue, LOW); digitalWrite(Yellow, LOW); }else{ //Read the values rval = analogRead(Redin); gval = analogRead(Greenin); bval = analogRead(Bluein); yval = analogRead(Yellowin); } if (rval > 1000){ digitalWrite(Red, HIGH); digitalWrite(Green, LOW); digitalWrite(Blue, LOW); digitalWrite(Yellow, LOW); digitalWrite(Alarm, LOW); delay(2000); } else if (gval > 1000){ digitalWrite(Red, LOW); digitalWrite(Green, HIGH); digitalWrite(Blue, LOW); digitalWrite(Yellow, LOW); digitalWrite(Alarm, LOW); delay(2000); } else if (bval > 1000){ digitalWrite(Red, LOW); digitalWrite(Green, LOW); digitalWrite(Blue, HIGH); digitalWrite(Yellow, LOW); digitalWrite(Alarm, LOW); delay(2000); } else if (yval > 1000){ digitalWrite(Red, LOW); digitalWrite(Green, LOW); digitalWrite(Blue, LOW); digitalWrite(Yellow, HIGH); digitalWrite(Alarm, LOW); delay(2000); } else{ digitalWrite(Red, LOW); digitalWrite(Green, LOW); digitalWrite(Blue, LOW); digitalWrite(Yellow, LOW); digitalWrite(Alarm, HIGH); delay (400); digitalWrite(Red, LOW); digitalWrite(Green, LOW); digitalWrite(Blue, LOW); digitalWrite(Yellow, LOW); digitalWrite(Alarm, LOW); delay (200); digitalWrite(Red, LOW); digitalWrite(Green, LOW); digitalWrite(Blue, LOW); digitalWrite(Yellow, LOW); digitalWrite(Alarm, HIGH); }
}
|