Switch Statement no breaking
i'm working on script uses irremote library https://github.com/shirriff/arduino-irremote i'm able receive signals remote. reason when send signal behaves if i'm sending same signal on , over.
for example if press on/off button remote toggles pin on , off every half second. same true if press button brings 0 255 in half second increments. in both scenarios goes on infinity.
i've tried adding , removing curled braces no luck. how can turn pins on , off 1 signal remote?
for example if press on/off button remote toggles pin on , off every half second. same true if press button brings 0 255 in half second increments. in both scenarios goes on infinity.
i've tried adding , removing curled braces no luck. how can turn pins on , off 1 signal remote?
code: [select]
#include <irremote.h>
int recv_pin = a1; // ir receiver
irrecv irrecv(recv_pin);
decode_results results;
int statled1 = 5; //led 1
int statled2 = 3; //led 2
int statled3 = 9; //led 3
int statled_state1 = low; //mac
int statled_state2 = low; //mac
int statled_state3 = low; //mac
int pins[] = { // array of pins
3, 5, 9};
int arraylevel = 0;
void setup() {
pinmode(recv_pin, input);
irrecv.enableirin(); // start receiver
pinmode(statled1, output);
pinmode(statled2, output);
pinmode(statled3, output);
pinmode(3, output);
pinmode(5, output);
pinmode(9, output);
digitalwrite(statled1, statled_state1); //mac
digitalwrite(statled2, statled_state2); //mac
digitalwrite(statled3, statled_state3); //mac
digitalwrite(3, low);
digitalwrite(5, low);
digitalwrite(9, low);
serial.begin(9600);
serial.println("waiting: ");
}
void loop() {
irrecv.decode(&results);
unsigned long key = results.value; //fetch key
if(key != 0) //ignore keys zero
{
serial.println("key recieved: ");
serial.println(key);
switch(key)
{
case 0xa55a21de:
if(statled_state1 != low)
statled_state1 = low;
else
statled_state1 = high;
digitalwrite(statled1, statled_state1); //mac
serial.println("on/off");
break;
case 0xa55a01fe:
serial.println("brightening lights up");
arraylevel = arraylevel + 10;
if (arraylevel < 0) arraylevel = 0;
if (arraylevel > 255) arraylevel = 255;
arraywriteanalog(arraylevel);
serial.println(arraylevel);
break;
case 0xa55a817e:
serial.println("dimming lights down");
arraylevel = arraylevel - 10;
if (arraylevel < 0) arraylevel = 0;
if (arraylevel > 255) arraylevel = 255;
arraywriteanalog(arraylevel);
serial.println(arraylevel);
break;
}
delay(500);
}
}
void arraywriteanalog(int val) {
val = constrain(val, 0, 200);
(int = 0; < sizeof(pins) / sizeof(int); i++) {
serial.print("analogwrite ");
serial.print(pins[i]);
serial.print(" ");
serial.println(val);
serial.flush();
analogwrite(pins[i], val);
}
}
void arraywrite(int pins[], int val) {
(int = 0; <= (sizeof(pins)/sizeof(int)); i++) {
digitalwrite(pins[i], val);
}
}
as code tags, think need call "resume"
Arduino Forum > Using Arduino > Programming Questions > Switch Statement no breaking
arduino
Comments
Post a Comment