65.6k views
1 vote
Write modified code that will generate a random number between 0 and 255 when a button is pressed and will write the number to the serial monitor as well as to the receiver Arduino.

User Carlota
by
8.2k points

1 Answer

5 votes

Solution :

#include<LiquidCrystal.h>

int value;

int flag;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()

{

lcd.begin(16, 2);

Serial.begin(9600);

}

void loop()

{

value=digitalRead(7);

if(value==0){

flag=1;}

if(value==1){

flag=~flag;}

if (flag==1){

lcd.setCursor(0,0);

lcd.print("number is");

lcd.setCursor(2,1);

lcd.print(random(0, 255));

delay(1000);

}

else{

lcd.setCursor(0,0);

lcd.print("Not Pressed");

delay(1000);

lcd.clear();}

}

User Nitrodist
by
7.5k points