#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int led = 13;
int push = 4;
int buzz = 7;
int button = 0;
int c = 261; int d = 293;
int e = 329;
int f = 349;
int g = 391;
int a = 440; int Bb = 466;
int b = 493;
int highc = 523;
int eighth = 500/2;
int quarter = 1000/2;
int half = 2000/2;
int numTones = 62;
void setup() {
{
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
pinMode(push,INPUT);
pinMode(buzz,OUTPUT);
pinMode(led, OUTPUT);
}
}
void loop() {
button = digitalRead(push);
if (button == HIGH){
digitalWrite(led, HIGH);
layar();
birthday();
sunshine();
}if (button == LOW); {
digitalWrite(led, LOW);
noTone(buzz);
}
}
void birthday(){
tone(buzz ,c,150*2);
delay(400);
tone(buzz,c,50*2);
delay(50*2);
tone(buzz,d,quarter);
delay(quarter);
tone(buzz,c,quarter);
delay(quarter);
tone(buzz,f,quarter);
delay(quarter);
tone(buzz,e,half);
delay(half);
tone(buzz,c,150*2);
delay(200*2);
tone(buzz,c,50*2);
delay(50*2);
tone(buzz,d,quarter);
delay(quarter);
tone(buzz,c,quarter);
delay(quarter);
tone(buzz,g,quarter);
delay(quarter);
tone(buzz,f,half);
delay(half);
tone(buzz,c,150*2);
delay(200*2);
tone(buzz,c,50*2);
delay(50*2);
tone(buzz,highc,quarter);
delay(quarter);
tone(buzz,a,quarter);
delay(quarter);
tone(buzz,f,quarter);
delay(quarter);
tone(buzz,e,quarter);
delay(quarter);
tone(buzz,d,half);
delay(half);
tone(buzz,Bb,150*2);
delay(200*2);
tone(buzz,Bb,50*2);
delay(50*2);
tone(buzz,a,quarter);
delay(quarter);
tone(buzz,f,quarter);
delay(quarter);
tone(buzz,g,quarter);
delay(quarter);
tone(buzz,f,half);
delay(half);
}
void sunshine(){
tone(buzz,d, 400);
delay(500);
tone(buzz, g, 300);
delay(500);
tone(buzz,a, 350);
delay(400);
tone(buzz,b, 500);
delay(500);
noTone(50*2);
tone(buzz, b, 600);
delay(300);
noTone(buzz);delay(100);
tone(buzz, b, 500);
delay(400);
noTone(buzz);delay(300);
tone(buzz,b, 350);
delay(400);
tone(buzz, a, 300);
delay(400);
tone(buzz,b, 350);
delay(400);
tone(buzz,g, 300);
noTone(buzz);delay(50);
tone(buzz, g, 300);
delay(400);
noTone(buzz); delay(100);
tone(buzz, g, 700);
noTone(buzz);
tone(buzz,g, 350);
delay(500);
tone(buzz, a, 300);
delay(500);
tone(buzz,b, 350);
delay(500);
tone(buzz,highc, 600);
delay(700);
tone(buzz, 659, 600);
delay(600);
tone(buzz,659, 350);
delay(600);
tone(buzz, 587, 300);
delay(500);
tone(buzz,highc, 350);
delay(500);
tone(buzz,b, 600);
delay(700);
noTone(buzz);delay(500);
tone(buzz,g, 350);
delay(600);
tone(buzz, a, 300);
delay(500);
tone(buzz,b, 350);
delay(500);
tone(buzz,highc, 600);
delay(700);
tone(buzz, 659, 600);
delay(600);
tone(buzz,659, 350);
delay(600);
tone(buzz, 587, 300);
delay(500);
tone(buzz,highc, 350);
delay(500);
tone(buzz,b, 600);
delay(700);
tone(buzz,g,700);
delay(600);
noTone(buzz);delay(500);
tone(buzz,g, 350);
delay(600);
tone(buzz, a, 300);
delay(500);
tone(buzz,b, 350);
delay(500);
tone(buzz,highc, 600);
delay(700);
tone(buzz, a, 600);
delay(600);
tone(buzz,a, 350);
delay(600);
noTone(buzz);delay(100);
tone(buzz, b, 300);
delay(500);
tone(buzz,g, 700);
delay(500);
while(1);
}
void layar()
{
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner
display.println("HAPPY BIRTHDAY"); //tulis tulisan "CNC STORE BANDUNG"
display.display();
}