~josealberto4444/arduino-quiz

ref: d5eaefd5530689ab21814ecdebe5abcda1f84738 arduino-quiz/questionsAndAnswers/questionsAndAnswers.ino -rw-r--r-- 1.5 KiB
d5eaefd5 — josealberto4444 Add welcome and link it to motion event 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);

void scrollHMessage(String message) {
  // Show a message scrolling horizontally along the first line of the screen
  String spaceFilling = "                ";
  message = spaceFilling + message + spaceFilling;
  for (int i = 0; i < message.length() - 14; i+=2) {
    lcd.setCursor(0, 0);
    lcd.print(message.substring(i, i+16));
    delay(400);
  }
}

void scrollVMessage(String message) {
  // Show a message scrolling vertically along the screen
  String spaceFilling = "                ";
  message = spaceFilling + message + spaceFilling;
  for (int i = 0; i < message.length() - 16; i+=16) {
    lcd.setCursor(0, 0);
    lcd.print(message.substring(i, i+16));
    lcd.setCursor(0, 1);
    lcd.print(message.substring(i+16, i+32));
    delay(1000);
  }
}

volatile bool motion = 0;

void detectMotion() {
  motion = true;
}

void welcome() {
  tone(8, 4978, 40);
  delay(100);
  tone(8, 4978, 40);
  lcd.clear();
  lcd.noBacklight();
  delay(300);
  lcd.backlight();
  delay(300);
  lcd.noBacklight();
  delay(300);
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hello!");
  delay(1000);
  motion = false;
}

void setup() {
  attachInterrupt(0, detectMotion, RISING);
  lcd.init();
  lcd.backlight();
}

void loop() {
  if (motion) welcome();
  delay(100);
//  scrollVMessage("This is quite a long message to show in this tiny screen. =P");
//  scrollHMessage("This is quite a long message to show in this tiny screen. =P");
}