SHARE
TWEET

Initialization/Setup

ChipSkylarkk Jun 16th, 2013 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Arduino controlled LED Pong
  3.  
  4. Designed and created by Schuyler Sowa
  5. http://www.instructables.com/member/Chip+Fixes/
  6. */
  7.  
  8. //You need to install these libraries on your computer
  9. #include "LPD8806.h"
  10. #include "SPI.h"
  11. #include <Wire.h>
  12. #include <LiquidCrystal_I2C.h>
  13.  
  14. //Scoreboard shift registers
  15. #define data1 5 //14
  16. #define clock1 7 //11
  17. #define latch1 6 //12
  18.  
  19. //hex values of scoreboard numbers (0-9)
  20. byte digitOne[10]= {0x6F, 0x09, 0x73, 0x3B, 0x1D, 0x3E, 0x7C, 0x0B, 0x7F, 0x1F}; //Player 1 numbers
  21. byte digitTwo[10]= {0x6F, 0x09, 0x73, 0x3B, 0x1D, 0x3E, 0x7C, 0x0B, 0x7F, 0x1F}; //Player 2 numbers
  22.  
  23. //Player 1 shift register
  24. #define data2 8
  25. #define clock2 9
  26. #define latch2 10
  27.  
  28. //Player 2 shift register
  29. #define data3 11
  30. #define clock3 12
  31. #define latch3 13
  32.  
  33. #define player1 1 //Player 1 push button
  34. #define player2 2 //Player 2 push button
  35. #define pot A2 //Adjusts speed of 'ball'
  36.  
  37. int nLEDs = 30; //Number of LEDs
  38. int dataPin  = 3; //LED Strip
  39. int clockPin = 4; //LED Strip
  40. LPD8806 strip = LPD8806(32, dataPin, clockPin);
  41.  
  42. char turn = 'A';
  43. char flag = 'N';
  44. char cheat = 'N';
  45. int i = 0;
  46. int j = 0;
  47. byte player1Points = 0;
  48. byte player2Points = 0;
  49. int score;
  50.  
  51. //LCD
  52. //Wire SDA to A4 and SCL to A5
  53. LiquidCrystal_I2C lcd(0x20,16,2);  //set the LCD address to 0x20 for a 16 chars and 2 line display
  54.  
  55. void setup()
  56. {
  57.   lcd.init(); //initialize lcd
  58.   lcd.backlight(); //turn on backlight
  59.  
  60.   pinMode(latch1, OUTPUT);
  61.   pinMode(clock1, OUTPUT);
  62.   pinMode(data1, OUTPUT);
  63.  
  64.   pinMode(latch2, OUTPUT);
  65.   pinMode(clock2, OUTPUT);
  66.   pinMode(data2, OUTPUT);
  67.  
  68.   pinMode(latch3, OUTPUT);
  69.   pinMode(clock3, OUTPUT);
  70.   pinMode(data3, OUTPUT);
  71.  
  72.   //Sets scoreboards to '0'
  73.   digitalWrite(latch1, LOW);
  74.   shiftOut(data1, clock1, MSBFIRST, ~digitOne[0]);
  75.   shiftOut(data1, clock1, MSBFIRST, ~digitTwo[0]);
  76.   digitalWrite(latch1, HIGH);
  77.  
  78.   //Turns off player1 and player2 LEDs
  79.   digitalWrite(latch2, LOW);
  80.   shiftOut(data2, clock2, MSBFIRST, 255);  
  81.   digitalWrite(latch2, HIGH);
  82.   digitalWrite(latch3, LOW);
  83.   shiftOut(data3, clock3, MSBFIRST, 255);  
  84.   digitalWrite(latch3, HIGH);
  85.  
  86.   pinMode(pot, INPUT);
  87.   strip.begin();
  88.   strip.show();
  89.   pinMode(player1, INPUT);
  90.   digitalWrite(player1, HIGH);
  91.   pinMode(player2, INPUT);
  92.   digitalWrite(player2, HIGH);
  93.  
  94.   score = selectScore(); //Sets the winning score
  95.  
  96.   //Turns on player1 LEDs
  97.   digitalWrite(latch2, LOW);
  98.   shiftOut(data2, clock2, MSBFIRST, 0);  
  99.   digitalWrite(latch2, HIGH);
  100. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top