Go Down

Topic: Simple reflex game WIP, 15 LED and one button with ATTinyx5 (Read 90 times) previous topic - next topic

wilykat

 A simple game resembling the classic Larson Scanner but one LED will be a different color.  The goal is to press the button when the odd colored LED is lit.

Code: [Select]
#define A 5
#define B 6
#define C 7
#define D 2
#define E 3

#define LED_COUNT 14
#define DDR_BYTE 0
#define PORT_BYTE 1

// need to set up delay variable and set pin 1 for button

byte matrix[LED_COUNT][2] = {
  //  DDR_BYTE   PORT_BYTE
  //     ABCDE       ABCDE
  { 0b00011000, 0b00010000 }, // AB 0 -
  { 0b00011000, 0b00001000 }, // BA 1 -
  { 0b00001100, 0b00001000 }, // BC 2 -
  { 0b00001100, 0b00000100 }, // CB 3 -
  { 0b00010100, 0b00010000 }, // AC 4 -
  { 0b00010100, 0b00000100 }, // CA 5 -
  { 0b00010010, 0b00010000 }, // AD 6 -
  { 0b00010010, 0b00000010 }, // DA 7 - middle LED will be different color
  { 0b00001010, 0b00001000 }, // BD 8 -
  { 0b00001010, 0b00000010 }, // DB 9 -
  { 0b00000110, 0b00000100 }, // CD 10 -
  { 0b00010001, 0b00010000 }, // AE 11 -
  { 0b00010001, 0b00000001 }, // EA 12 -
  { 0b00001001, 0b00001000 }, // BE 13 -
  { 0b00001001, 0b00000001 }  // EB 14 -

};

void setup() {}

void loop() {
  for ( byte l = 0; l < LED_COUNT; l++ ) {
    turnOn( l );
    delay( 10 );
  }
  for ( byte l = LED_COUNT; l > 0; l-- ) {
    turnOn( l );
    delay( 10 );
  }
}

void turnOn( byte led ) {
  DDRB = matrix[led][DDR_BYTE];
  PORTB = matrix[led][PORT_BYTE];
}

void button() {
// to be added
// debounce button
// which LED was lit?
// if (l) = 7 then blink it
// then stay here (and blink) until the button is pressed again
// decrement delay value, no lower than 1 (insanely fast)
}





Tentative (I know it's missing decoupling cap in schematic), the ATTiny will be programmed separately then installed in socket. To do: add in button check code and stop LED (jump to a different subroutine) and if the stopped LED is the odd colored LED, blink it. Otherwise do nothing until the button is pressed again to play again. 

Maybe change delay to a variable, decrease the value every time the user gets the right LED?  Powering it off will reset to original higher delay value.

Go Up