const int redPin = 13;
const int greenPin = 12;
const int bluePin = 11;
const int speaker = 10;
const int buttonPin1 = 2; // increase the counter
const int buttonPin2 = 3; // Decrease the counter
const int buttonPin3 = 4;
const int buttonPin4 = 5; // increase the counter
const int buttonPin5 = 6; // Decrease the counter
const int buttonPin6 = 7;
const int buttonPin7 = 8;
const int buttonPin8 = 9;
// Variabel button
int button1; int button2;
int button3; int button4;
int button5; int button6;
int button7; int button8;
int lastState1 = LOW;
int currentState1;
void setup() {
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(speaker, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPin6, INPUT);
pinMode(buttonPin7, INPUT);
pinMode(buttonPin8, INPUT);
}
void loop() {
button1 = digitalRead(buttonPin1);
button2 = digitalRead(buttonPin2);
button3 = digitalRead(buttonPin3);
button4 = digitalRead(buttonPin4);
button5 = digitalRead(buttonPin5);
button6 = digitalRead(buttonPin6);
button7 = digitalRead(buttonPin7);
button8 = digitalRead(buttonPin8);
if(lastState1 == HIGH && button1 == LOW){
}
else if(lastState1 == LOW && button1 == HIGH){
}
lastState1 = button1;
// if(button1 == HIGH) {
// DO();
// setColor(255, 0, 0); // Red Color
// }
if(button2 == HIGH) {
RE();
setColor(0, 255, 0); // Green Color
}
if(button3 == HIGH) {
MI();
setColor(0, 0, 255); // Blue Color
}
if(button4 == HIGH) {
FA();
setColor(255, 255, 255); // White Color
}
if(button5 == HIGH) {
SOL();
setColor(170, 0, 255); // Purple Color
}
if(button6 == HIGH) {
LA();
setColor(255, 255 , 0); // Yellow color
}
if(button7 == HIGH) {
SI();
setColor(0, 255, 255); // cyan color
}
if(button8 == HIGH) {
DOO();
setColor(0, 255, 0); // Green Color
}
delay(10);
}
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
void DO() {
tone(speaker, 264);
}
void RE() {
tone(speaker, 297);
}
void MI() {
tone(speaker, 330);
}
void FA() {
tone(speaker, 352);
}
void SOL() {
tone(speaker, 396);
}
void LA() {
tone(speaker, 440);
}
void SI() {
tone(speaker, 495);
}
void DOO() {
tone(speaker, 528);
}
void DIAM() {
noTone(speaker);
}