I am writing a code that needs to read the analog inputs from pins A0-A7. Pins A4-A7 work off of the W102 (U2) module. I can easily read the inputs from A0-A3 but the rest are stuck at 1023 units when I have any voltage placed on the pin. If I remove voltage it drops to 0 units. The same thing has happened on 2 separate Nano's that I have tried. There is no in between. My code below works on an Uno however so I am very confused. Can anyone please help me understand what the issue is?
//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);
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.