Hi i am pretty new to programming (as in this is my first project ever).
Unfortunately I also have a decently hard project in which I am hooking up addressable LED’s on my bike. this is one of the easier parts but I can not find any information on it. I wanted to change the sequence the lights are going through with on-off toggle switches like the one shown below.
I am curious if anyone could tell me how to write a program that when all are in off position no lights are on, when toggle switch 1 is on and the rest are off mode 1 is running, when toggle switch 2 is on and the rest are off mode 2 is running. I have 5 toggle switches and also if its possible would like to have it so that say, toggle switch 1 and 2 are on and the rest are off mode 6 is running .
Sure, do something like this. Wire the switches to Gnd on one side, and to a pin on the other.
Then for code:
btye sw0 = 2;
byte sw1 = 3;
byte sw2 = 4;
byte sw3 = 5;
byte sw4 = 6;
byte sw5 = 7;
pinMode (sw0, INPUT_PULLUP); // set as inputs with internal pullup resistors
pinMode (sw1, INPUT_PULLUP); // open switch = 1, closed switch = 0
pinMode (sw2, INPUT_PULLUP);
pinMode (sw3, INPUT_PULLUP);
pinMode (sw4, INPUT_PULLUP);
pinMode (sw5, INPUT_PULLUP);
combined = PIND; // read port D where D7 thry D0 are
combined = combined >>2; // shift right 2 bits, D1-D0 are not used
// now do something based on switch contents
// all closed
// sw0 open
// sw1 open
// sw2 open
// sw3 open
// sw4 open
// sw 5 open
// whatever combinations you want to support
// can write as case 0b00xxxxxx:
// to make it easier to visualize where the open & closed switches are
} // end switch
// whatever other code you're running
} // end loop