/*
Playing Notes based on sliding pot position
https://wokwi.com/projects/351175246893548120
by dlloydev, December 2022.
*/
#include <pwmWrite.h>
const int tonePin = 4;
const int potPin = 12;
const int notes = 8;
const note_t cScale[notes] = { NOTE_C, NOTE_D, NOTE_E, NOTE_F, NOTE_G, NOTE_A, NOTE_B, NOTE_C };
const int cScaleOctaves[notes] = { 4, 4, 4, 4, 4, 4, 4, 5 };
const int duration = 500; // note duration ms
const int interval = 0; // pause between notes ms
Pwm pwm = Pwm(); // constructor
void setup() {
pinMode(potPin, INPUT); // sliding pot input
pwm.attach(potPin, 4); // attach to channel 4
}
void loop() {
int sensorVal = analogRead(potPin);
int scale = map(sensorVal, 0, 4095, 0, notes - 1);
note_t note = cScale[scale];
int octave = cScaleOctaves[scale];
pwm.note(tonePin, note, octave, duration, interval); // auto attaches to ch 0
delay(10);
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
bz1:1
bz1:2
pot1:VCC
pot1:SIG
pot1:GND