Hi makers,
I'm working on the high-striker carnival game and would like help with coding the device.
The design of the project comprises of a micro switches at specified intervals on a scale to identify the location of the bearing and LEDs are used to represent the location of bearing.
Once a contestant hits the striker the metal bearing goes up the scale, as the bearing makes contact with the switches, they are used to trigger the subsequent LEDs sequentially as the switches are triggered.
After the switches are triggered, LEDs turn on and have to stay ON for about 3 seconds and sequentially switch-off in the reverse direction.
int s[7];
const int pincount = 6;
const int in[7] = {21, 20, 19, 18, 17, 16, 15};
const int out[7] = {13, 12, 11, 10, 9, 8, 7};
void setup() {
// defining the states of the pins
for (int pinin =0; pinin < pincount; pinin++) {pinMode(in[pinin], INPUT);}
for (int pinout =0; pinout < pincount; pinout++) {pinMode(out[pinout], OUTPUT);}
}
void loop() {
s[0] = digitalRead(in[0]);
s[1] = digitalRead(in[1]);
s[2] = digitalRead(in[2]);
s[3] = digitalRead(in[3]);
s[4] = digitalRead(in[4]);
s[5] = digitalRead(in[5]);
s[6] = digitalRead(in[6]);
if (s[0] == HIGH){digitalWrite(out[0], HIGH);}
if (s[1] == HIGH){digitalWrite(out[1], HIGH);}
if (s[2] == HIGH){digitalWrite(out[2], HIGH);}
if (s[3] == HIGH){digitalWrite(out[3], HIGH);}
if (s[4] == HIGH){digitalWrite(out[4], HIGH);}
if (s[5] == HIGH){digitalWrite(out[5], HIGH);}
if (s[6] == HIGH){digitalWrite(out[6], HIGH);}
delay(1000);
digitalWrite(out[6], LOW);
delay(1100);
digitalWrite(out[6], LOW);
delay(1200);
digitalWrite(out[6], LOW);
delay(1300);
digitalWrite(out[6], LOW);
delay(1400);
digitalWrite(out[6], LOW);
delay(1500);
digitalWrite(out[6], LOW);
delay(1600);
digitalWrite(out[6], LOW);
}
sketch_sep16a.ino (1.58 KB)