/*LCD-Hello_world.ino
Modified By: Ho Yun "Bobby" Chan
SparkFun Electronics
Date: 5/22/2019
License: This code is public domain.
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time since the Arduino was turned on.
Hardware Hookup:
lCD VSS pin to GND
LCD VCC pin to 5V
10k Potentiometer to LCD VO pin (pin 3)
LCD RS pin to digital pin 13
LCD R/W pin to GND
LCD Enable pin to digital pin 12
.
.
.
LCD D4 pin to digital pin 11
LCD D5 pin to digital pin 10
LCD D6 pin to digital pin 9
LCD D7 pin to digital pin 8
LCD-Backlight - Anode to 10K resistor to +5V (optional depending on your LCD)
LCD Backlight - K to GND
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld=
https://learn.sparkfun.com/tutorials/basic-character-lcd-hookup-guide
*/
// include the library code:
#include <LiquidCrystal.h>
//initialize the library by associating any needed LCD interface pin
//with the arduino pin number it is connected to
const int buttonPin = 2;
const int tonePin = 3;
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
long randNumber;
int buttonState = 0;
int y = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
//set up the LCD's number of columns and rows:
lcd.begin(16, 2);
//randomSeed(analogRead(0));
//Print a message to the LCD.
lcd.print("Solar Powered!");
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
//set the cursor to column 0, line 1
//(note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
if (buttonState == HIGH) {
delay(1000);
lcd.clear();
lcd.print("Playing...");
//randNumber = random(0,3);
//Serial.println(randNumber);
lcd.setCursor(0,1);
//lcd.print(randNumber);
//if (randNumber == 0) {
tone(3, 523.25, 225);
delay(250);
tone(3, 440, 225);
delay(250);
tone(3, 523.25, 225);
delay(250);
tone(3, 698.46, 225);
delay(250);
tone(3, 523.25, 225);
delay(250);
tone(3, 440, 225);
delay(250);
tone(3, 523.25, 225);
delay(250);
tone(3, 659.25, 225);
delay(250);
tone(3, 554.37, 225);
delay(250);
tone(3, 440, 225);
delay(250);
tone(3, 554.37, 225);
delay(250);
tone(3, 659.25, 225);
delay(250);
tone(3, 554.37, 225);
delay(250);
tone(3, 440, 225);
delay(250);
tone(3, 554.37, 225);
delay(250);
tone(3, 659.25, 225);
delay(250);
tone(3, 554.37, 225);
delay(250);
tone(3, 440, 225);
delay(250);
tone(3, 554.37, 225);
delay(250);
tone(3, 659.25, 400);
delay(500);
tone(3, 880, 400);
delay(500);
tone(8, 698.46, 225);
//
delay(250);
tone(8, 587.33, 225);
delay(250);
tone(8, 698.46, 225);
delay(250);
tone(8, 1046.50, 225);
delay(250);
tone(8, 659.25, 225);
delay(250);
tone(8, 554.37, 225);
delay(250);
tone(8, 880, 225);
delay(250);
tone(8, 1108.73, 225);
delay(250);
tone(8, 2349.32, 900);
delay(1000);
tone(8, 110, 900);
delay(1000);
}
else {
int x = 0;
lcd.setCursor(0,0);
lcd.print("Solar Powered");
lcd.setCursor(0, 1);
lcd.print("Press here! -->");
//x = x + (millis()/1000) - y;
//lcd.print(x);
noTone(3);
}
}
Comments