Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the library code:
- #include <LiquidCrystal.h>
- int playerOnePin = A0; // select the input pin for the potentiometer
- int playerTwoPin = A1;
- int ledPin = 9; // select the pin for the LED
- int ledPin2 = 10;
- // Pin 13: Arduino has an LED connected on pin 13
- // Pin 11: Teensy 2.0 has the LED on pin 11
- // Pin 6: Teensy++ 2.0 has the LED on pin 6
- int playerOneScore = 0; // variable to store the value coming from the sensor
- int playerTwoScore = 0;
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- void setup() {
- // declare the ledPin as an OUTPUT:
- pinMode(ledPin, OUTPUT);
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- // Print a message to the LCD.
- lcd.print("hello, world!");
- lcd.display();
- analogWrite(ledPin, 0);
- analogWrite(ledPin2, 0);
- }
- void loop() {
- // read the value from the sensor:
- playerOneScore = analogRead(playerOnePin);
- playerTwoScore = analogRead(playerTwoPin);
- lcd.clear();
- boolean oneWinning = playerOneScore > playerTwoScore;
- if(oneWinning){
- lcd.print("Player 1 ");
- analogWrite(ledPin, 2^(playerOneScore-playerTwoScore));
- analogWrite(ledPin2, 0);
- lcd.print(playerOneScore-playerTwoScore);
- }
- else{
- lcd.print("Player 2 ");
- analogWrite(ledPin2, 2^(playerTwoScore-playerOneScore));
- analogWrite(ledPin, 0);
- lcd.print(playerTwoScore-playerOneScore);
- }
- delay(200);
- }
Advertisement
Add Comment
Please, Sign In to add comment