Advertisement
ChipSkylarkk

Shield Test

Jun 10th, 2013
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.89 KB | None | 0 0
  1. /*
  2. Shield Test
  3. This does not test LED Strip or potentiometer but the scoreboards should both show '0' and the LCD should be telling you how to select the score.
  4. */
  5.  
  6. //You need to install these libraries on your computer
  7. #include "LPD8806.h"
  8. #include "SPI.h"
  9. #include <Wire.h>
  10. #include <LiquidCrystal_I2C.h>
  11.  
  12. //Scoreboard shift registers
  13. #define data1 5 //14
  14. #define clock1 7 //11
  15. #define latch1 6 //12
  16.  
  17. //hex values of numbers
  18. byte digitOne[10]= {0x6F, 0x09, 0x73, 0x3B, 0x1D, 0x3E, 0x7C, 0x0B, 0x7F, 0x1F}; //Player 1 numbers
  19. byte digitTwo[10]= {0x6F, 0x09, 0x73, 0x3B, 0x1D, 0x3E, 0x7C, 0x0B, 0x7F, 0x1F}; //Player 2 numbers
  20.  
  21. #define player1 1 //button player 1
  22. #define player2 2 //button player 2
  23. #define pot A2 //adjust speed of 'ball'
  24.  
  25. int nLEDs = 32; //Number of LEDs
  26. int dataPin  = 3; //LED Strip
  27. int clockPin = 4; //LED Strip
  28. LPD8806 strip = LPD8806(32, dataPin, clockPin);
  29.  
  30. char turn = 'A';
  31. char flag = 'N';
  32. char cheat = 'N';
  33. int i = 0;
  34. int j = 0;
  35. byte player1Points = 0;
  36. byte player2Points = 0;
  37. int score;
  38.  
  39. //Connect SDA to A4 and SCL to A5
  40. LiquidCrystal_I2C lcd(0x20,16,2);  //set the LCD address to 0x20 for a 16 chars and 2 line display
  41.  
  42. void setup()
  43. {
  44.   lcd.init(); //initialize lcd
  45.   lcd.backlight(); //turn on backlight
  46.  
  47.   pinMode(latch1, OUTPUT);
  48.   pinMode(clock1, OUTPUT);
  49.   pinMode(data1, OUTPUT);
  50.  
  51.   //sets scoreboards to '0'
  52.   digitalWrite(latch1, LOW);
  53.   shiftOut(data1, clock1, MSBFIRST, ~digitOne[0]);
  54.   shiftOut(data1, clock1, MSBFIRST, ~digitTwo[0]);
  55.   digitalWrite(latch1, HIGH);
  56.  
  57.   pinMode(pot, INPUT);
  58.   strip.begin();
  59.   strip.show();
  60.   pinMode(player1, INPUT);
  61.   digitalWrite(player1, HIGH);
  62.   pinMode(player2, INPUT);
  63.   digitalWrite(player2, HIGH);
  64. }
  65.  
  66. void loop()
  67. {
  68.   score = selectScore(); //Sets the winning score
  69. }
  70.  
  71. int selectScore()
  72. {
  73.   lcd.print("Player 1, select");
  74.   lcd.setCursor(0, 1);
  75.   lcd.print("score limit by");
  76.   delay(3000);
  77.   lcd.setCursor(1,0);
  78.   lcd.clear();
  79.   lcd.print("pressing button.");
  80.   delay(3000);
  81.   lcd.setCursor(1,0);
  82.   lcd.clear();
  83.   lcd.print("Player 2");
  84.   lcd.setCursor(0,1);
  85.   lcd.print("confirms by");
  86.   delay(3000);
  87.   lcd.setCursor(1,0);
  88.   lcd.clear();
  89.   lcd.print("pressing their");
  90.   lcd.setCursor(0,1);
  91.   lcd.print("button.");
  92.   delay(3000);
  93.   lcd.clear();
  94.  
  95.   int i;
  96.   int buttonState;
  97.   int lastButtonState;
  98.   int buttonPushCounter=0;
  99.   int confirm;
  100.   for (i=0;i<9999;i++) //is there a better way to do this?
  101.   {
  102.     delay(100);
  103.     buttonState = digitalRead(player1);
  104.     confirm = digitalRead(player2);
  105.     if (buttonState != lastButtonState) {
  106.     if (buttonState == LOW) {
  107.       buttonPushCounter++;
  108.       lcd.clear();
  109.       lcd.print(buttonPushCounter);
  110.     }
  111.   }
  112.   lastButtonState = buttonState;
  113.   if (buttonPushCounter == 9)
  114.   {
  115.     buttonPushCounter = 0;
  116.   }
  117.   if (confirm == LOW)
  118.   {
  119.     lcd.clear();
  120.     return buttonPushCounter;
  121.   }
  122.   }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement