Monday, 26 September 2016

Lesson 9: Activity 2(ii) (Buttons)

Lesson 9 
Activity 2 Part (ii) - Buttons

Codes:

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int readkey;
void setup() {
  lcd.begin(16, 2);
  lcd.print("How are you");
  lcd.setCursor(0, 1);
  lcd.print("today?");
}
void loop()
{
  readkey=analogRead(0);
  if (readkey<50) {
  lcd.clear();
  lcd.print("Happy");
  }
  else if(readkey<195) {
    lcd.clear();
    lcd.print("Sad");
  }
  else if(readkey<380) {
    lcd.clear();
    lcd.print("Excited");
  }
  else if(readkey<790) {
    lcd.clear();
    lcd.print("Bored");
  }
}

No comments:

Post a Comment