Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int pot = A5;
- const int piezo = 13;
- int led, val, value, tono;
- const int gap = 100;
- unsigned long previous = 0;
- bool flag = 0;
- // TONES: note, period & frequency.
- int c = 3830; // 261 Hz
- int d = 3400; // 294 Hz
- int e = 3038; // 329 Hz
- int f = 2864; // 349 Hz
- int g = 2550; // 392 Hz
- int A = 2272; // 440 Hz
- int B = 2028; // 493 Hz
- int C = 1912; // 523 Hz
- int D = 1704; // 587 Hz
- int E = 1517; // 659 Hz
- int F = 1432; // 698 Hz
- int G = 1275; // 784 Hz
- int note[] = {c,d,e,f,g,A,B,C,D,E,F,G};
- void setup() {
- for (led = 2; led <= 12; led++)
- pinMode(led, OUTPUT);
- pinMode(pot, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- val = analogRead(piezo);
- value = map(val, 0, 1023, 1, 12);
- for (led = 2; led <= 12; led++) {
- if ((led > value-2) && (led < value+2))
- digitalWrite(led, HIGH);
- else
- digitalWrite(led, LOW);
- }
- tono = map(val, 0, 1023, 11, 0);
- if (millis() - previous >= gap) {
- previous = millis();
- if (flag == 0) {
- flag = 1;
- tone(piezo, note[tono]);
- }
- else {
- flag = 0;
- noTone(piezo);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement