Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Wire dexterity game with 2 difficult level
- // There are 2 wire loops, one on the left and one on the right.
- // The wire loop must be moved from side to side and back so that it does not touch the wire running in the center.
- // If you touch it, a counter will indicate hit.
- // That when we get back to the starting point, we will indicate this by the wire reels on the opposite side.
- // We get the final score and after a while the game starts again.
- // Have fun!
- #include <Arduino.h>
- #include <TM1637Display.h>
- #define CLK 8
- #define DIO 9
- #define easyPin 7
- #define hardPin 6
- #define tonePin 5
- bool easy=false, play=false;
- uint8_t counter;
- const uint8_t SEG_DONE[] = {
- SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
- SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
- SEG_C | SEG_E | SEG_G, // n
- SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E
- };
- const uint8_t SEG_EASY[] = {
- SEG_A | SEG_F | SEG_G | SEG_E | SEG_D, // E
- SEG_A | SEG_B | SEG_C | SEG_G | SEG_E | SEG_F, // A
- SEG_A | SEG_F | SEG_G | SEG_C | SEG_D, // S
- SEG_F | SEG_G | SEG_B | SEG_C | SEG_D // Y
- };
- const uint8_t SEG_HARD[] = {
- SEG_B | SEG_F | SEG_G | SEG_E | SEG_C, // H
- SEG_A | SEG_B | SEG_C | SEG_G | SEG_E | SEG_F, // A
- SEG_E | SEG_G, // r
- SEG_B | SEG_C | SEG_D | SEG_E | SEG_G // d
- };
- const uint8_t SEG_HI[] = {
- 0, //
- SEG_B | SEG_F | SEG_G | SEG_E | SEG_C, // H
- SEG_B | SEG_C, // I
- 0 //
- };
- const uint8_t SEG_SEG[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F};
- uint8_t SEG_WE[] = { SEG_A, SEG_A, SEG_A, SEG_A };
- TM1637Display display(CLK, DIO);
- void setup() {
- Serial.begin(115200);
- Serial.println("Start ...");
- pinMode(easyPin,INPUT_PULLUP);
- pinMode(hardPin,INPUT_PULLUP);
- pinMode(tonePin,OUTPUT);
- pinMode(4,OUTPUT); // speaker GND
- display.setBrightness(0x0f);
- display.setSegments(SEG_HI);
- delay(1000);
- wfs();
- }
- void wfs() { //waiting for start
- display.clear();
- counter=0;
- easy=false;
- while (!play) {
- if (digitalRead(easyPin)==0 or digitalRead(hardPin)==0) {
- tone(tonePin,440,200);
- if (digitalRead(easyPin)==0) easy=true;
- play=true;
- }
- SEG_WE[0]=SEG_SEG[counter];
- SEG_WE[1]=SEG_SEG[counter];
- SEG_WE[2]=SEG_SEG[counter];
- SEG_WE[3]=SEG_SEG[counter];
- display.setSegments(SEG_WE);
- delay(200);
- counter++;
- if (counter==6) counter=0;
- }
- if (easy) {
- display.setSegments(SEG_EASY);
- delay(1000);
- } else {
- display.setSegments(SEG_HARD);
- delay(1000);
- }
- delay(1000);
- display.showNumberDec(3333, true);
- tone(tonePin,440,200);
- delay(500);
- display.showNumberDec(2222, true);
- tone(tonePin,500,200);
- delay(500);
- display.showNumberDec(1111, true);
- tone(tonePin,600,200);
- delay(500);
- display.clear();
- counter=0;
- }
- void loop() {
- display.showNumberDec(counter, false);
- if (play==false) {
- wfs();
- }
- if (play==true and easy==true and digitalRead(easyPin)==LOW) { // Easy mode, and detect easy pin contact, --> miss
- counter++;
- tone(tonePin,800,200);
- delay(500);
- }
- if (play==true and easy==true and digitalRead(hardPin)==LOW) { // Easy mode, and detect hard pin contact, --> end game
- tone(tonePin,440,200);
- display.clear();
- display.setSegments(SEG_DONE);
- delay(1000);
- display.setSegments(SEG_EASY);
- delay(500);
- display.showNumberDec(counter, false);
- delay(500);
- display.clear();
- display.setSegments(SEG_EASY);
- delay(500);
- display.showNumberDec(counter, false);
- delay(500);
- display.clear();
- display.setSegments(SEG_EASY);
- delay(500);
- display.showNumberDec(counter, false);
- delay(500);
- display.clear();
- delay(500);
- play=false;
- }
- if (play==true and easy==false and digitalRead(hardPin)==LOW) { // Hard mode, and detect hard pin contact, --> miss
- counter++;
- tone(tonePin,800,200);
- delay(500);
- }
- if (play==true and easy==false and digitalRead(easyPin)==LOW) { // Hard mode, and detect easy pin contact, --> end game
- tone(tonePin,440,200);
- display.clear();
- display.setSegments(SEG_DONE);
- delay(1000);
- display.setSegments(SEG_HARD);
- delay(500);
- display.showNumberDec(counter, false);
- delay(500);
- display.clear();
- display.setSegments(SEG_HARD);
- delay(500);
- display.showNumberDec(counter, false);
- delay(500);
- display.clear();
- display.setSegments(SEG_HARD);
- delay(500);
- display.showNumberDec(counter, false);
- delay(500);
- display.clear();
- delay(500);
- play=false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement