awinograd

Thumb War!

Apr 25th, 2012
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. // include the library code:
  2. #include <LiquidCrystal.h>
  3.  
  4. int playerOnePin = A0;    // select the input pin for the potentiometer
  5. int playerTwoPin = A1;
  6. int ledPin = 9;      // select the pin for the LED
  7. int ledPin2 = 10;
  8. // Pin 13: Arduino has an LED connected on pin 13
  9. // Pin 11: Teensy 2.0 has the LED on pin 11
  10. // Pin 6: Teensy++ 2.0 has the LED on pin 6
  11. int playerOneScore = 0;  // variable to store the value coming from the sensor
  12. int playerTwoScore = 0;
  13. // initialize the library with the numbers of the interface pins
  14. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  15.  
  16. void setup() {
  17.   // declare the ledPin as an OUTPUT:
  18.   pinMode(ledPin, OUTPUT);  
  19.   // set up the LCD's number of columns and rows:
  20.   lcd.begin(16, 2);
  21.   // Print a message to the LCD.
  22.   lcd.print("hello, world!");  
  23.   lcd.display();
  24.   analogWrite(ledPin, 0);
  25.   analogWrite(ledPin2, 0);
  26. }
  27.  
  28. void loop() {
  29.   // read the value from the sensor:
  30.   playerOneScore = analogRead(playerOnePin);
  31.   playerTwoScore = analogRead(playerTwoPin);
  32.   lcd.clear();
  33.   boolean oneWinning = playerOneScore > playerTwoScore;
  34.   if(oneWinning){
  35.     lcd.print("Player 1 ");
  36.     analogWrite(ledPin, 2^(playerOneScore-playerTwoScore));
  37.     analogWrite(ledPin2, 0);
  38.     lcd.print(playerOneScore-playerTwoScore);
  39.   }
  40.   else{
  41.     lcd.print("Player 2 ");
  42.     analogWrite(ledPin2, 2^(playerTwoScore-playerOneScore));
  43.     analogWrite(ledPin, 0);
  44.     lcd.print(playerTwoScore-playerOneScore);
  45.   }
  46.  
  47.   delay(200);  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment