ese111digipoker / Bet_Chip.ino
Bet_Chip.ino
Raw
// Code for the Bet Chip: Master
// Should Update & Send Info to Holdings Chip via I2C
// Integrate this with holdings chip, send initial holdings value over 
 
#include <LiquidCrystal.h>
#include <Wire.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int button = 7;
int val; 
int count = 0;
int currentState = 0; 
int lastState = 0;
bool bPress = false;

//
int holdings = 0; 
int betInc = 0;


void setup() {
  Serial.begin(9600);
  Wire.begin(); 
  
  // Begin Game, ask for holdings and bet increment 
  Serial.println("Welcome to DigiPoker!"); 
  Serial.println("Please input your initial holdings and your bet increment value (separated by a space): "); 
  while (Serial.available() == 0) {
  }
  holdings = Serial.parseFloat(); //Read the data the user has input
  betInc = Serial.parseFloat(); //Read the data the user has input
  Serial.print("Your holdings: $" ); //Prompt User for Input
  Serial.println(holdings); //Prompt User for Input
  Serial.print("Your bet increment: $" ); //Prompt User for Input
  Serial.println(betInc); //Prompt User for Input

  // Send initial holdings to other arduino
  
  
  delay(500);



  pinMode(button, INPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("Bet:$ ");
  lcd.setCursor(5,0);
  lcd.print(count);
}

void loop() {
  checkPress();
  if(bPress){
      bPress = false;
      lcd.setCursor(5,0);
      lcd.print("               ");
      lcd.setCursor(5,0);
      lcd.print(count);
      Serial.println(holdings);
  Wire.beginTransmission(9); // transmit to device #9
  Wire.write(holdings);              // sends x 
  Wire.endTransmission();    // stop transmitting
//  Wire.requestFrom(9, 6);    // request 6 bytes from slave device #8
//  while (Wire.available()) { // slave may send less than requested
//    char x = Wire.read(); // receive a byte as character
//    Serial.print(x);         // print the character
//  }
 }
}
void checkPress() { 
   currentState = digitalRead(button);
   if (currentState != lastState) { 
    if (currentState == LOW) { 
      bPress = true;
      count = count + betInc;
      holdings = holdings - betInc;
    } else { 
    //  Serial.println("off");
    }  
    delay(50);
}
    lastState = currentState;
}