Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Shield Test
- 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.
- */
- //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 numbers
- 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
- #define player1 1 //button player 1
- #define player2 2 //button player 2
- #define pot A2 //adjust speed of 'ball'
- int nLEDs = 32; //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;
- //Connect 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);
- //sets scoreboards to '0'
- digitalWrite(latch1, LOW);
- shiftOut(data1, clock1, MSBFIRST, ~digitOne[0]);
- shiftOut(data1, clock1, MSBFIRST, ~digitTwo[0]);
- digitalWrite(latch1, HIGH);
- pinMode(pot, INPUT);
- strip.begin();
- strip.show();
- pinMode(player1, INPUT);
- digitalWrite(player1, HIGH);
- pinMode(player2, INPUT);
- digitalWrite(player2, HIGH);
- }
- void loop()
- {
- score = selectScore(); //Sets the winning score
- }
- int selectScore()
- {
- lcd.print("Player 1, select");
- lcd.setCursor(0, 1);
- lcd.print("score limit by");
- delay(3000);
- lcd.setCursor(1,0);
- lcd.clear();
- lcd.print("pressing button.");
- delay(3000);
- lcd.setCursor(1,0);
- lcd.clear();
- lcd.print("Player 2");
- lcd.setCursor(0,1);
- lcd.print("confirms by");
- delay(3000);
- lcd.setCursor(1,0);
- lcd.clear();
- lcd.print("pressing their");
- lcd.setCursor(0,1);
- lcd.print("button.");
- delay(3000);
- lcd.clear();
- int i;
- int buttonState;
- int lastButtonState;
- int buttonPushCounter=0;
- int confirm;
- for (i=0;i<9999;i++) //is there a better way to do this?
- {
- delay(100);
- buttonState = digitalRead(player1);
- confirm = digitalRead(player2);
- if (buttonState != lastButtonState) {
- if (buttonState == LOW) {
- buttonPushCounter++;
- lcd.clear();
- lcd.print(buttonPushCounter);
- }
- }
- lastButtonState = buttonState;
- if (buttonPushCounter == 9)
- {
- buttonPushCounter = 0;
- }
- if (confirm == LOW)
- {
- lcd.clear();
- return buttonPushCounter;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement