Kaushik. T.S
Published © MIT

DIGITAL TOSSER (Using Arduino UNO)

Toss the coin digitally using digital tosser.

BeginnerFull instructions provided1 hour4
DIGITAL TOSSER (Using Arduino UNO)

Things used in this project

Story

Read more

Schematics

Fritizing circuit

Code

Arduno code

C/C++
#include <LiquidCrystal.h>
int contrast=75;//Set LCD contrast
const int buttonpin=8;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  analogWrite(9, contrast);
  lcd.begin(16, 2);
  pinMode(buttonpin,INPUT);//Button pin as input
  lcd.setCursor(0,0);//Set cursor to column 0, line 0
  lcd.print("Lets start toss");
  delay(1000); 
}

void loop() {
  
int  buttonState=digitalRead(buttonpin);
  int r=random(1,3);//Random nuber generation between 1-3
  lcd.setCursor(0,0);// set the cursor to column 0, line 0
  lcd.print("For H press Key");//For Heads press key
  lcd.setCursor(0,1);
  lcd.print("Dont press for L");//For Tails don't press key
  delay(3000);
  lcd.clear();
  
  lcd.setCursor(0,1);
  if ((buttonState==HIGH)&&(r==1))//Button High and random number=1
  lcd.print("Heads,You won");
  else if((buttonState==LOW)&&(r==2))//Button Low and random number =2
  lcd.print("Tails,You won");
  else
  lcd.print("You lost");//Can be button High ,random number=2 or LOw and r=1
  delay(10000); 
  lcd.clear();
}

Credits

Kaushik. T.S

Kaushik. T.S

2 projects • 6 followers
Presently I am pursuing BE in Electronics and communications from NIE Institute of technology,Mysuru

Comments