Código
- Nervers_meter_score.ino
- score_display.ino
- game.ino
angry_meter_score.ino Arduino
int latchPin =3; // ST_CP [RCK] em 74HC595int clockPin =4; // SH_CP [SCK] em 74HC595int dataPin =2; // DS [S1] em 74HC595const int STOP_LED =6; const int GO_LED =7; const int BUZZ =8; const int TOUCH =10; const int fail_threshold =9; enum Status {STOP =0, GO =1}; vazio setup () {Serial.begin (9600); displayInitialSetup (); gameInitialSetup ();} Status status =GO; int failCounter =0; void loop () {while (failCounter> fail_threshold) {gameover (); } switch (status) {case GO:digitalWrite (GO_LED, HIGH); digitalWrite (STOP_LED, LOW); digitalWrite (BUZZ, LOW); if (digitalRead (TOUCH) ==HIGH) {status =STOP; } pausa; caso STOP:digitalWrite (GO_LED, LOW); failCounter ++; if (failCounter> fail_threshold) break; displayDigit (failCounter); Serial.println (failCounter); failAlarm (); status =GO; pausa; }} byte seg_spin [6] ={B10000000, B01000000, B00100000, B00010000, B00001000, B00000100}; void gameover () {for (int i =0; i <6; i ++) {digitalWrite (BUZZ, HIGH); atraso (5); digitalWrite (BUZZ, LOW); atraso (50); digitalWrite (latchPin, LOW); shiftOut (dataPin, clockPin, LSBFIRST, seg_spin [i]); digitalWrite (latchPin, HIGH); atraso (10); }}
score_display.ino Arduino
byte seg_digits [10] ={B11111100, // =0 B01100000, // =1 B11011010, // =2 B11110010, // =3 B01100110, // =4 B10110110, // =5 B10111110, // =6 B11100000, // =7 B11111110, // =8 B11100110 // =9}; void displayDigit (int x) {digitalWrite (latchPin, LOW); shiftOut (dataPin, clockPin, LSBFIRST, seg_digits [x]); digitalWrite (latchPin, HIGH);} void displayInitialSetup () {pinMode (latchPin, OUTPUT); pinMode (dataPin, OUTPUT); pinMode (clockPin, OUTPUT); displayDigit (0);}
game.ino Arduino
void gameInitialSetup () {pinMode (STOP_LED, OUTPUT); pinMode (GO_LED, OUTPUT); pinMode (BUZZ, OUTPUT); pinMode (TOQUE, ALTO); digitalWrite (TOUCH, LOW);} void failAlarm () {digitalWrite (STOP_LED, HIGH); bip(); atraso (150); digitalWrite (STOP_LED, LOW); digitalWrite (BUZZ, LOW); atraso (500);} bip vazio () {para (int i =0; i <3; i ++) {digitalWrite (BUZZ, HIGH); atraso (50); digitalWrite (BUZZ, LOW); atraso (50); }}