Introduction: Arduinogame for Beginners
A simple but fun wack-a-mole look a like. The leds are HIGH for a certain time and your job is to hit the right botton during this time to get a point.
Step 1: Things You Need for This Project
The tings you need to complete this project is:
Arduino uno
A piezo
8 buttons
8 lamps
A shiftregister
and a lot of cables..
Step 2: Putting It Together
Choose a big breadboard so that you have a lot of space and easily can correct an error that easily can occure while having a lot of cables. Look at the circuts and look up ShiftOut arudino.cc if needed.
Step 3: The Code, Not Too Hard and Not Too Long!
//Pin connected to ST_CP of 74HC595
int latchPin = 13;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
int interval = 2000;
byte ledarray[8]={B00000001,B00000010,B00000100,B00001000,B00010000,B00100000,B01000000,B10000000}; byte pointsarray[8]={ B00000001,B00000010,B00000100,B00001000,B00010000,B00100000,B01000000,B10000000};
int knapp1 = 2;
int knapp2 = 3;
int knapp3 = 4;
int knapp4 = 5;
int knapp5 = 6;
int knapp6 = 7;
int knapp7 = 8;
int knapp8 = 9;
int lednr;
int pinCount=8;
int points=0;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
pinMode(5,INPUT_PULLUP);
pinMode(6,INPUT_PULLUP);
pinMode(7,INPUT_PULLUP);
pinMode(8,INPUT_PULLUP);
pinMode(9,INPUT_PULLUP);
Serial.begin(9600);
void loop() { for (int i=0; i<17; i++) { int prevMillis = millis(); lednr = random(8);
Serial.print(lednr);
// take the latchPin low so the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, ledarray[lednr]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
//delay(50); while((millis() - prevMillis) < interval){ if (digitalRead(lednr+2) == LOW){ points++; tone(10,440,300); delay(30); break; } } //while Serial.println (points); } }