From cac31726a254f6f490351f32baed384b53f1c76e Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Thu, 17 Dec 2020 09:09:41 -0800 Subject: [PATCH 1/8] New combined demo showing most non I2C input sensors. It'd be great to query I2C too, but those sensors unfortunately are not setup to use a different I2C address and conflict with one another unless you put some solder bridges to change the address --- examples/Combined_Demo/Combined_Demo.ino | 96 ++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 examples/Combined_Demo/Combined_Demo.ino diff --git a/examples/Combined_Demo/Combined_Demo.ino b/examples/Combined_Demo/Combined_Demo.ino new file mode 100644 index 0000000..be0febd --- /dev/null +++ b/examples/Combined_Demo/Combined_Demo.ino @@ -0,0 +1,96 @@ +// Combined Demo by Marc MERLIN + +#include "Arduino_SensorKit.h" + +uint8_t button = 4; +uint8_t led = 6; +uint8_t pot = A0; +uint8_t mic = A2; +uint8_t light = A3; + +void setup() { + #if 0 + // Accelerometer and Oled both share the same I2C address + // both cannot be used at the same time, unless you solder + // across the I2C address solder pads on the Oled module + Accelerometer.begin(); + // Same problem with pressure sensor + Pressure.begin(); + #endif + + pinMode(mic , INPUT); + pinMode(light , INPUT); + + pinMode(button , INPUT); + pinMode(led, OUTPUT); + digitalWrite(led, LOW); + + Environment.begin(); + + Oled.begin(); + Oled.setFlipMode(true); +} + +void loop() { + + Oled.setFont(u8x8_font_amstrad_cpc_extended_r); + + #if 0 + Oled.setCursor(0, 0); + Oled.print("x:"); + Oled.print(Accelerometer.readX()); + Oled.print(" "); + Oled.print("y:"); + Oled.print(Accelerometer.readY()); + Oled.print(" "); + Oled.print("z:"); + Oled.print(Accelerometer.readZ()); + // Similar problem with pressure sensor + Oled.print(Pressure.readAltitude()); + #endif + + Oled.setCursor(0, 0); + Oled.print("But:"); + if (digitalRead(button)) { + digitalWrite(led, HIGH); + Oled.print("1"); + } else { + digitalWrite(led, LOW); + Oled.print("0"); + } + + // https://github.com/olikraus/u8g2/wiki/u8x8reference#print + // looks like we need an offset of 9 for a font of 8 + // if the offset is wrong, the text gets displayed on + // the wrong line + uint16_t pot_value = analogRead(pot); + Oled.setCursor(0, 9); + Oled.print("Pot: "); + Oled.print(pot_value); + Oled.print(" "); + + uint16_t mic_value = analogRead(mic); + Oled.setCursor(0, 18); + Oled.print("Mic: "); + Oled.print(mic_value); + Oled.print(" "); + + uint16_t light_value = analogRead(light); + Oled.setCursor(0, 27); + Oled.print("Light: "); + Oled.print(light_value); + Oled.print(" "); + + Oled.setCursor(0, 45); + Oled.print("Temp:"); + Oled.print(Environment.readTemperature()); + Oled.print("C"); + + Oled.setCursor(0, 54); + Oled.print("Hum: "); + Oled.print(Environment.readHumidity()); + Oled.print("%"); + + Oled.refreshDisplay(); + delay(100); +} From 5e1fccb03d538432f50849732e9885e381f8f697 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Fri, 18 Dec 2020 07:45:30 -0800 Subject: [PATCH 2/8] Added I2C scanner for debug. --- examples/Combined_Demo/Combined_Demo.ino | 62 +++++++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/examples/Combined_Demo/Combined_Demo.ino b/examples/Combined_Demo/Combined_Demo.ino index be0febd..d281af3 100644 --- a/examples/Combined_Demo/Combined_Demo.ino +++ b/examples/Combined_Demo/Combined_Demo.ino @@ -7,16 +7,58 @@ uint8_t led = 6; uint8_t pot = A0; uint8_t mic = A2; uint8_t light = A3; + +// From https://playground.arduino.cc/Main/I2cScanner/ +// learn more about I2C here +// https://www.seeedstudio.com/blog/2019/09/25/uart-vs-i2c-vs-spi-communication-protocols-and-uses/ +// Scanner from https://github.com/RobTillaart/Arduino/blob/master/sketches/MultiSpeedI2CScanner/MultiSpeedI2CScanner.ino +// 30038 25 0x19 V V V V V V V V +// 30133 60 0x3C V V V V V V V V +// 30296 119 0x77 V V V V V V V V +void i2c_scan() { + uint8_t error, address, nDevices; + + Wire.begin(); + Serial.println("Scanning..."); + + nDevices = 0; + for(address = 1; address < 127; address++ ) + { + //Serial.println("I2C scan"); + // The i2c_scanner uses the return value of + // the Write.endTransmisstion to see if + // a device did acknowledge to the address. + Wire.beginTransmission(address); + error = Wire.endTransmission(); + + if (error == 0) + { + Serial.print("I2C device found at address 0x"); + if (address<16) + Serial.print("0"); + Serial.print(address,HEX); + Serial.println(" !"); + + nDevices++; + } + else if (error==4) + { + Serial.print("Unknown error at address 0x"); + if (address<16) + Serial.print("0"); + Serial.println(address,HEX); + } + } + if (nDevices == 0) + Serial.println("No I2C devices found\n"); + else + Serial.println("done\n"); +} void setup() { - #if 0 - // Accelerometer and Oled both share the same I2C address - // both cannot be used at the same time, unless you solder - // across the I2C address solder pads on the Oled module - Accelerometer.begin(); - // Same problem with pressure sensor - Pressure.begin(); - #endif + Serial.begin(115200); + // Running scan stops the OLED from working + //i2c_scan(); pinMode(mic , INPUT); pinMode(light , INPUT); @@ -29,6 +71,10 @@ void setup() { Oled.begin(); Oled.setFlipMode(true); + + // Enabling any of those 2 stops the OLED from working + //Accelerometer.begin(); + //Pressure.begin(); } void loop() { From cb7fbd766e63782c475213b78d98926a8d58fa14 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Fri, 18 Dec 2020 07:45:30 -0800 Subject: [PATCH 3/8] Added I2C scanner for debug + fixed diplay offset + add tone. When pushing the button, output a tone. --- examples/Combined_Demo/Combined_Demo.ino | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/Combined_Demo/Combined_Demo.ino b/examples/Combined_Demo/Combined_Demo.ino index d281af3..8ec844a 100644 --- a/examples/Combined_Demo/Combined_Demo.ino +++ b/examples/Combined_Demo/Combined_Demo.ino @@ -1,6 +1,7 @@ // Combined Demo by Marc MERLIN #include "Arduino_SensorKit.h" +#define BUZZER 5 uint8_t button = 4; uint8_t led = 6; @@ -75,6 +76,8 @@ void setup() { // Enabling any of those 2 stops the OLED from working //Accelerometer.begin(); //Pressure.begin(); + + pinMode(BUZZER, OUTPUT); } void loop() { @@ -95,48 +98,47 @@ void loop() { Oled.print(Pressure.readAltitude()); #endif + // when using u8g8 instead of u8g2, cursor values + // are in characters, not pixels Oled.setCursor(0, 0); Oled.print("But:"); if (digitalRead(button)) { digitalWrite(led, HIGH); Oled.print("1"); + tone(BUZZER, 440); } else { digitalWrite(led, LOW); Oled.print("0"); + noTone(BUZZER); } - // https://github.com/olikraus/u8g2/wiki/u8x8reference#print - // looks like we need an offset of 9 for a font of 8 - // if the offset is wrong, the text gets displayed on - // the wrong line uint16_t pot_value = analogRead(pot); - Oled.setCursor(0, 9); + Oled.setCursor(0, 1); Oled.print("Pot: "); Oled.print(pot_value); Oled.print(" "); uint16_t mic_value = analogRead(mic); - Oled.setCursor(0, 18); + Oled.setCursor(0, 2); Oled.print("Mic: "); Oled.print(mic_value); Oled.print(" "); uint16_t light_value = analogRead(light); - Oled.setCursor(0, 27); + Oled.setCursor(0, 3); Oled.print("Light: "); Oled.print(light_value); Oled.print(" "); - Oled.setCursor(0, 45); + Oled.setCursor(0, 6); Oled.print("Temp:"); Oled.print(Environment.readTemperature()); Oled.print("C"); - Oled.setCursor(0, 54); + Oled.setCursor(0, 7); Oled.print("Hum: "); Oled.print(Environment.readHumidity()); Oled.print("%"); - Oled.refreshDisplay(); delay(100); } From 687d40b6b7cbe979be41168c2c0fd16f3d8a4eb8 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Fri, 18 Dec 2020 07:45:30 -0800 Subject: [PATCH 4/8] Added I2C scanner for debug + fixed diplay offset + add tone. When pushing the button, output a tone. Show buzzer tone on screen. --- examples/Combined_Demo/Combined_Demo.ino | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/Combined_Demo/Combined_Demo.ino b/examples/Combined_Demo/Combined_Demo.ino index 8ec844a..0012fd9 100644 --- a/examples/Combined_Demo/Combined_Demo.ino +++ b/examples/Combined_Demo/Combined_Demo.ino @@ -100,23 +100,25 @@ void loop() { // when using u8g8 instead of u8g2, cursor values // are in characters, not pixels + uint16_t pot_value = analogRead(pot); + Oled.setCursor(0, 0); Oled.print("But:"); + if (digitalRead(button)) { digitalWrite(led, HIGH); Oled.print("1"); - tone(BUZZER, 440); + tone(BUZZER, pot_value); } else { digitalWrite(led, LOW); Oled.print("0"); noTone(BUZZER); } - uint16_t pot_value = analogRead(pot); Oled.setCursor(0, 1); - Oled.print("Pot: "); + Oled.print("BuzPot: "); Oled.print(pot_value); - Oled.print(" "); + Oled.print("Hz "); uint16_t mic_value = analogRead(mic); Oled.setCursor(0, 2); From b32d82b5c0752290cbfc2b7411d5c4a965ea3da2 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Tue, 12 Jan 2021 15:44:18 -0800 Subject: [PATCH 5/8] Added code to show pressure and accelerometer Depends on patch in https://github.com/arduino-libraries/Arduino_SensorKit/compare/main...arduino-libraries:display_hw_i2c?expand=1 --- examples/Combined_Demo/Combined_Demo.ino | 199 +++++++++++------------ 1 file changed, 97 insertions(+), 102 deletions(-) diff --git a/examples/Combined_Demo/Combined_Demo.ino b/examples/Combined_Demo/Combined_Demo.ino index 0012fd9..a203dd3 100644 --- a/examples/Combined_Demo/Combined_Demo.ino +++ b/examples/Combined_Demo/Combined_Demo.ino @@ -1,146 +1,141 @@ -// Combined Demo by Marc MERLIN - +// Combined Demo by Marc MERLIN + #include "Arduino_SensorKit.h" -#define BUZZER 5 - +#define BUZZER 5 + uint8_t button = 4; uint8_t led = 6; -uint8_t pot = A0; -uint8_t mic = A2; -uint8_t light = A3; - -// From https://playground.arduino.cc/Main/I2cScanner/ -// learn more about I2C here -// https://www.seeedstudio.com/blog/2019/09/25/uart-vs-i2c-vs-spi-communication-protocols-and-uses/ -// Scanner from https://github.com/RobTillaart/Arduino/blob/master/sketches/MultiSpeedI2CScanner/MultiSpeedI2CScanner.ino +uint8_t pot = A0; +uint8_t mic = A2; +uint8_t light = A3; + +// From https://playground.arduino.cc/Main/I2cScanner/ +// learn more about I2C here +// https://www.seeedstudio.com/blog/2019/09/25/uart-vs-i2c-vs-spi-communication-protocols-and-uses/ +// Scanner from https://github.com/RobTillaart/Arduino/blob/master/sketches/MultiSpeedI2CScanner/MultiSpeedI2CScanner.ino // 30038 25 0x19 V V V V V V V V // 30133 60 0x3C V V V V V V V V // 30296 119 0x77 V V V V V V V V -void i2c_scan() { - uint8_t error, address, nDevices; - - Wire.begin(); - Serial.println("Scanning..."); - - nDevices = 0; - for(address = 1; address < 127; address++ ) - { - //Serial.println("I2C scan"); - // The i2c_scanner uses the return value of - // the Write.endTransmisstion to see if - // a device did acknowledge to the address. - Wire.beginTransmission(address); - error = Wire.endTransmission(); - - if (error == 0) - { - Serial.print("I2C device found at address 0x"); - if (address<16) - Serial.print("0"); - Serial.print(address,HEX); - Serial.println(" !"); - - nDevices++; - } - else if (error==4) - { - Serial.print("Unknown error at address 0x"); - if (address<16) - Serial.print("0"); - Serial.println(address,HEX); - } - } - if (nDevices == 0) - Serial.println("No I2C devices found\n"); - else - Serial.println("done\n"); -} +void i2c_scan() { + uint8_t error, address, nDevices; + + Wire.begin(); + Serial.println("Scanning..."); + + nDevices = 0; + for(address = 1; address < 127; address++ ) + { + //Serial.println("I2C scan"); + // The i2c_scanner uses the return value of + // the Write.endTransmisstion to see if + // a device did acknowledge to the address. + Wire.beginTransmission(address); + error = Wire.endTransmission(); + + if (error == 0) + { + Serial.print("I2C device found at address 0x"); + if (address<16) + Serial.print("0"); + Serial.print(address,HEX); + Serial.println(" !"); + + nDevices++; + } + else if (error==4) + { + Serial.print("Unknown error at address 0x"); + if (address<16) + Serial.print("0"); + Serial.println(address,HEX); + } + } + if (nDevices == 0) + Serial.println("No I2C devices found\n"); + else + Serial.println("done\n"); +} void setup() { - Serial.begin(115200); - // Running scan stops the OLED from working - //i2c_scan(); - + Serial.begin(115200); + // Running scan stops the OLED from working + //i2c_scan(); + pinMode(mic , INPUT); pinMode(light , INPUT); - + pinMode(button , INPUT); pinMode(led, OUTPUT); digitalWrite(led, LOW); - + Environment.begin(); - + Oled.begin(); Oled.setFlipMode(true); - - // Enabling any of those 2 stops the OLED from working - //Accelerometer.begin(); - //Pressure.begin(); - - pinMode(BUZZER, OUTPUT); + + Accelerometer.begin(); + Pressure.begin(); + + pinMode(BUZZER, OUTPUT); } void loop() { - + Oled.setFont(u8x8_font_amstrad_cpc_extended_r); - #if 0 - Oled.setCursor(0, 0); - Oled.print("x:"); - Oled.print(Accelerometer.readX()); - Oled.print(" "); - Oled.print("y:"); - Oled.print(Accelerometer.readY()); - Oled.print(" "); - Oled.print("z:"); - Oled.print(Accelerometer.readZ()); - // Similar problem with pressure sensor - Oled.print(Pressure.readAltitude()); - #endif - - // when using u8g8 instead of u8g2, cursor values - // are in characters, not pixels - uint16_t pot_value = analogRead(pot); - Oled.setCursor(0, 0); Oled.print("But:"); - + + uint16_t pot_value = analogRead(pot); if (digitalRead(button)) { digitalWrite(led, HIGH); Oled.print("1"); - tone(BUZZER, pot_value); + tone(BUZZER, pot_value); } else { digitalWrite(led, LOW); Oled.print("0"); - noTone(BUZZER); + noTone(BUZZER); } - + Oled.setCursor(0, 1); Oled.print("BuzPot: "); Oled.print(pot_value); - Oled.print("Hz "); - - uint16_t mic_value = analogRead(mic); + Oled.print("Hz "); + + uint16_t mic_value = analogRead(mic); Oled.setCursor(0, 2); Oled.print("Mic: "); Oled.print(mic_value); - Oled.print(" "); - - uint16_t light_value = analogRead(light); + Oled.print(" "); + + uint16_t light_value = analogRead(light); Oled.setCursor(0, 3); Oled.print("Light: "); Oled.print(light_value); - Oled.print(" "); - - Oled.setCursor(0, 6); - Oled.print("Temp:"); - Oled.print(Environment.readTemperature()); + Oled.print(" "); + + // when using u8g8 instead of u8g2, cursor values + // are in characters, not pixels + Oled.setCursor(0, 4); + Oled.print("x:"); + Oled.print(Accelerometer.readX()); + Oled.print(" y:"); + Oled.print(Accelerometer.readY()); + Oled.setCursor(0, 5); + Oled.print("z:"); + Oled.print(Accelerometer.readZ()); + Oled.print(" T:"); + Oled.print(Environment.readTemperature()); Oled.print("C"); - - Oled.setCursor(0, 7); + + Oled.setCursor(0, 6); Oled.print("Hum: "); - Oled.print(Environment.readHumidity()); + Oled.print(Environment.readHumidity()); Oled.print("%"); - + + Oled.setCursor(0, 7); + Oled.print("Alt:"); + Oled.print(Pressure.readAltitude()); + delay(100); } From ec8fe6c7053e35a17d1df9673d12d3f3b3d278d8 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Tue, 12 Jan 2021 16:08:06 -0800 Subject: [PATCH 6/8] Work around I2c hang by spacing out reads to different devices. --- examples/Combined_Demo/Combined_Demo.ino | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/Combined_Demo/Combined_Demo.ino b/examples/Combined_Demo/Combined_Demo.ino index a203dd3..d10ee8f 100644 --- a/examples/Combined_Demo/Combined_Demo.ino +++ b/examples/Combined_Demo/Combined_Demo.ino @@ -82,6 +82,22 @@ void setup() { void loop() { Oled.setFont(u8x8_font_amstrad_cpc_extended_r); + + // when using u8g8 instead of u8g2, cursor values + // are in characters, not pixels + Oled.setCursor(0, 4); + // If accelerometer and altimeter are queried too close to one another + // this causes a hang, so we read this first. + Oled.print("x:"); + Oled.print(Accelerometer.readX()); + Oled.print(" y:"); + Oled.print(Accelerometer.readY()); + Oled.setCursor(0, 5); + Oled.print("z:"); + Oled.print(Accelerometer.readZ()); + Oled.print(" T:"); + Oled.print(Environment.readTemperature()); + Oled.print("C"); Oled.setCursor(0, 0); Oled.print("But:"); @@ -114,20 +130,6 @@ void loop() { Oled.print(light_value); Oled.print(" "); - // when using u8g8 instead of u8g2, cursor values - // are in characters, not pixels - Oled.setCursor(0, 4); - Oled.print("x:"); - Oled.print(Accelerometer.readX()); - Oled.print(" y:"); - Oled.print(Accelerometer.readY()); - Oled.setCursor(0, 5); - Oled.print("z:"); - Oled.print(Accelerometer.readZ()); - Oled.print(" T:"); - Oled.print(Environment.readTemperature()); - Oled.print("C"); - Oled.setCursor(0, 6); Oled.print("Hum: "); Oled.print(Environment.readHumidity()); From 0c4797db7451128eeaa4837bca463a104bf2dae7 Mon Sep 17 00:00:00 2001 From: Marc MERLIN Date: Tue, 12 Jan 2021 16:11:32 -0800 Subject: [PATCH 7/8] Re-enable I2C scan, it works without killing the OLED screen. --- examples/Combined_Demo/Combined_Demo.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/Combined_Demo/Combined_Demo.ino b/examples/Combined_Demo/Combined_Demo.ino index d10ee8f..ba0a782 100644 --- a/examples/Combined_Demo/Combined_Demo.ino +++ b/examples/Combined_Demo/Combined_Demo.ino @@ -25,7 +25,6 @@ void i2c_scan() { nDevices = 0; for(address = 1; address < 127; address++ ) { - //Serial.println("I2C scan"); // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. @@ -59,7 +58,7 @@ void i2c_scan() { void setup() { Serial.begin(115200); // Running scan stops the OLED from working - //i2c_scan(); + i2c_scan(); pinMode(mic , INPUT); pinMode(light , INPUT); From a135ba89cb21434a42eef8467eabc3746b90d95a Mon Sep 17 00:00:00 2001 From: marqdevx <11246294+marqdevx@users.noreply.github.com> Date: Wed, 13 Jan 2021 15:14:42 +0100 Subject: [PATCH 8/8] Update Combined_Demo.ino --- examples/Combined_Demo/Combined_Demo.ino | 114 ++++++++--------------- 1 file changed, 37 insertions(+), 77 deletions(-) diff --git a/examples/Combined_Demo/Combined_Demo.ino b/examples/Combined_Demo/Combined_Demo.ino index ba0a782..e1ffc7d 100644 --- a/examples/Combined_Demo/Combined_Demo.ino +++ b/examples/Combined_Demo/Combined_Demo.ino @@ -1,72 +1,33 @@ // Combined Demo by Marc MERLIN +// Reviewed by Pablo Marquínez +// This demo use all the devices from the Arduino SensorKit +// Showing the values on the Display #include "Arduino_SensorKit.h" + #define BUZZER 5 +#define BUTTON 4 +#define LED 6 +#define POT A0 +#define MIC A2 +#define LIGHT A3 -uint8_t button = 4; -uint8_t led = 6; -uint8_t pot = A0; -uint8_t mic = A2; -uint8_t light = A3; - -// From https://playground.arduino.cc/Main/I2cScanner/ -// learn more about I2C here -// https://www.seeedstudio.com/blog/2019/09/25/uart-vs-i2c-vs-spi-communication-protocols-and-uses/ -// Scanner from https://github.com/RobTillaart/Arduino/blob/master/sketches/MultiSpeedI2CScanner/MultiSpeedI2CScanner.ino -// 30038 25 0x19 V V V V V V V V -// 30133 60 0x3C V V V V V V V V -// 30296 119 0x77 V V V V V V V V -void i2c_scan() { - uint8_t error, address, nDevices; - - Wire.begin(); - Serial.println("Scanning..."); - - nDevices = 0; - for(address = 1; address < 127; address++ ) - { - // The i2c_scanner uses the return value of - // the Write.endTransmisstion to see if - // a device did acknowledge to the address. - Wire.beginTransmission(address); - error = Wire.endTransmission(); - - if (error == 0) - { - Serial.print("I2C device found at address 0x"); - if (address<16) - Serial.print("0"); - Serial.print(address,HEX); - Serial.println(" !"); - - nDevices++; - } - else if (error==4) - { - Serial.print("Unknown error at address 0x"); - if (address<16) - Serial.print("0"); - Serial.println(address,HEX); - } - } - if (nDevices == 0) - Serial.println("No I2C devices found\n"); - else - Serial.println("done\n"); -} +int pot_value; +bool button_state; +int mic_value; +int light_value; void setup() { - Serial.begin(115200); - // Running scan stops the OLED from working - i2c_scan(); - - pinMode(mic , INPUT); - pinMode(light , INPUT); - - pinMode(button , INPUT); - pinMode(led, OUTPUT); - digitalWrite(led, LOW); - + Serial.begin(9600); + + pinMode(MIC , INPUT); + pinMode(LIGHT , INPUT); + pinMode(BUTTON , INPUT); + + pinMode(LED, OUTPUT); + digitalWrite(LED, LOW); + pinMode(BUZZER, OUTPUT); + Environment.begin(); Oled.begin(); @@ -74,17 +35,14 @@ void setup() { Accelerometer.begin(); Pressure.begin(); - - pinMode(BUZZER, OUTPUT); } void loop() { - Oled.setFont(u8x8_font_amstrad_cpc_extended_r); - - // when using u8g8 instead of u8g2, cursor values - // are in characters, not pixels + + //cursor values are in characters, not pixels Oled.setCursor(0, 4); + // If accelerometer and altimeter are queried too close to one another // this causes a hang, so we read this first. Oled.print("x:"); @@ -101,29 +59,31 @@ void loop() { Oled.setCursor(0, 0); Oled.print("But:"); - uint16_t pot_value = analogRead(pot); - if (digitalRead(button)) { - digitalWrite(led, HIGH); - Oled.print("1"); + pot_value = analogRead(POT); + + button_state = digitalRead(BUTTON); + Oled.print(button_state); + + if (button_state == true) { + digitalWrite(LED, HIGH); tone(BUZZER, pot_value); } else { - digitalWrite(led, LOW); - Oled.print("0"); + digitalWrite(LED, LOW); noTone(BUZZER); } - + Oled.setCursor(0, 1); Oled.print("BuzPot: "); Oled.print(pot_value); Oled.print("Hz "); - uint16_t mic_value = analogRead(mic); + mic_value = analogRead(MIC); Oled.setCursor(0, 2); Oled.print("Mic: "); Oled.print(mic_value); Oled.print(" "); - uint16_t light_value = analogRead(light); + light_value = analogRead(LIGHT); Oled.setCursor(0, 3); Oled.print("Light: "); Oled.print(light_value);