//Below is my code testing only pin A6
#include <WiFiNINA.h>
#include <SPI.h>
const int outpin3 = 3;// the number of the buzzer pin
const int inpin2 = 2;
//const int inpin4 = 4;
// Variables will change:
int speed1 = LOW;
int speed2 = LOW;
int speed3 = LOW;
unsigned long previousMillis_1 = 0;
unsigned long previousMillis_2 = 0;
unsigned long previousMillis_3 = 0;
// constants won't change:
const long interval_1 = 1000;
const long interval_2 = 500;
const long interval_3 = 100;
void setup() {
// put your setup code here, to run once:
pinMode(A6, INPUT);
pinMode(outpin3, OUTPUT);
pinMode(inpin2, INPUT);
Serial.begin(9600);
}
void loop() {
//SLOW BUZZING "TIMER"
unsigned long currentMillis_1 = millis();
unsigned long currentMillis_2 = millis();
unsigned long currentMillis_3 = millis();
// read the input on analog pin 0:
int longRangeValue_3 = analogRead(A6);
int val = map(longRangeValue_3,0,1023,0,1023);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
//float voltageLong_3 = longRangeValue_3 * (5.0 / 1023.0);
if (currentMillis_1 - previousMillis_1 >= interval_1) {
// save the last time you blinked the LED
previousMillis_1 = currentMillis_1;
// if the LED is off turn it on and vice-versa:
if (speed1 == LOW) {
speed1 = HIGH;
}
else {
speed1 = LOW;
}
}
//MEDIUM BUZZING "TIMER"
if (currentMillis_2 - previousMillis_2 >= interval_2) {
// save the last time you blinked the LED
previousMillis_2 = currentMillis_2;
// if the LED is off turn it on and vice-versa:
if (speed2 == LOW) {
speed2 = HIGH;
}
else {
speed2 = LOW;
}
}
//FAST BUZZING "TIMER"
if(currentMillis_3 - previousMillis_3 >= interval_3) {
// save the last time you blinked the LED
previousMillis_3 = currentMillis_3;
// if the LED is off turn it on and vice-versa:
if (speed3 == LOW){
speed3 = HIGH;
}
else{
speed3 = LOW;
}
}
if(analogRead(A6) <= 570){
digitalWrite(outpin3, speed1);
}
else if(analogRead(A6) > 570){
digitalWrite(outpin3, speed3);
}
Serial.println(val);
}