Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Arduino controlled LED Pong
- Designed and created by Schuyler Sowa
- http://www.instructables.com/member/Chip+Fixes/
- */
- //You need to install these libraries on your computer
- #include "LPD8806.h"
- #include "SPI.h"
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- //Scoreboard shift registers
- #define data1 5 //14
- #define clock1 7 //11
- #define latch1 6 //12
- //hex values of scoreboard numbers (0-9)
- byte digitOne[10]= {0x6F, 0x09, 0x73, 0x3B, 0x1D, 0x3E, 0x7C, 0x0B, 0x7F, 0x1F}; //Player 1 numbers
- byte digitTwo[10]= {0x6F, 0x09, 0x73, 0x3B, 0x1D, 0x3E, 0x7C, 0x0B, 0x7F, 0x1F}; //Player 2 numbers
- //Player 1 shift register
- #define data2 8
- #define clock2 9
- #define latch2 10
- //Player 2 shift register
- #define data3 11
- #define clock3 12
- #define latch3 13
- #define player1 1 //Player 1 push button
- #define player2 2 //Player 2 push button
- #define pot A2 //Adjusts speed of 'ball'
- int nLEDs = 30; //Number of LEDs
- int dataPin = 3; //LED Strip
- int clockPin = 4; //LED Strip
- LPD8806 strip = LPD8806(32, dataPin, clockPin);
- char turn = 'A';
- char flag = 'N';
- char cheat = 'N';
- int i = 0;
- int j = 0;
- byte player1Points = 0;
- byte player2Points = 0;
- int score;
- //LCD
- //Wire SDA to A4 and SCL to A5
- LiquidCrystal_I2C lcd(0x20,16,2); //set the LCD address to 0x20 for a 16 chars and 2 line display
- void setup()
- {
- lcd.init(); //initialize lcd
- lcd.backlight(); //turn on backlight
- pinMode(latch1, OUTPUT);
- pinMode(clock1, OUTPUT);
- pinMode(data1, OUTPUT);
- pinMode(latch2, OUTPUT);
- pinMode(clock2, OUTPUT);
- pinMode(data2, OUTPUT);
- pinMode(latch3, OUTPUT);
- pinMode(clock3, OUTPUT);
- pinMode(data3, OUTPUT);
- //Sets scoreboards to '0'
- digitalWrite(latch1, LOW);
- shiftOut(data1, clock1, MSBFIRST, ~digitOne[0]);
- shiftOut(data1, clock1, MSBFIRST, ~digitTwo[0]);
- digitalWrite(latch1, HIGH);
- //Turns off player1 and player2 LEDs
- digitalWrite(latch2, LOW);
- shiftOut(data2, clock2, MSBFIRST, 255);
- digitalWrite(latch2, HIGH);
- digitalWrite(latch3, LOW);
- shiftOut(data3, clock3, MSBFIRST, 255);
- digitalWrite(latch3, HIGH);
- pinMode(pot, INPUT);
- strip.begin();
- strip.show();
- pinMode(player1, INPUT);
- digitalWrite(player1, HIGH);
- pinMode(player2, INPUT);
- digitalWrite(player2, HIGH);
- score = selectScore(); //Sets the winning score
- //Turns on player1 LEDs
- digitalWrite(latch2, LOW);
- shiftOut(data2, clock2, MSBFIRST, 0);
- digitalWrite(latch2, HIGH);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement