ese111digipoker / Holdings_Chip.ino
Holdings_Chip.ino
Raw
// Code for the Holdings Chip: Slave
// Should Receive & Update Info from Bet Chip via I2C
// Integrate this with bet chip, receive initial holdings value and decrement by bet val 
 

#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int state = 0;
int holdings = 0;
void setup() {
  Serial.begin(9600);
  // Start the I2C Bus as Slave on address 9
  Wire.begin(9);
  // Attach a function to trigger when something is received.
  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);

// Screen Setup
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("Holdings:$ ");
  lcd.setCursor(10,0);
  lcd.print(holdings);
}
void requestEvent()
{
  
}
void receiveEvent(int bytes) {
  holdings = Wire.read();  
  Serial.println(holdings);
}
void loop() {
      lcd.setCursor(10,0);
      lcd.print("               ");
      lcd.setCursor(10,0);
      lcd.print(holdings);
      Serial.println(holdings);
      delay(1000);
}