Hello,
This is my first post and I am a complete beginner.
My problem with the code which I will post below is that pinMode 4 works perfectly fine before I included the code that gives me real time temperature feedback over wifi.
I cant figure out why the new code would be blocking pinMode from working but I think the problem is originating in void setup()
Any help would be greatly appreciated.
const unsigned long onTime = 500; /*latch on*/
const unsigned long offTime = 43200000; /*latch off*/
unsigned long previousMillis=0;
unsigned long interval = onTime;
boolean gate_solenoid=true;
#include <SPI.h>
#include <WiFiNINA.h>
#define sensorPin A0
char ssid[] = "wifi_name";
char pass[] = "wifi_password";
int keyIndex = 0;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup(){
pinMode(4,OUTPUT);
Serial.begin(9600);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
}
server.begin();
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
void loop(){
int reading = analogRead(sensorPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
float temperatureC = (voltage - 0.5) * 100 ;
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n') {
if (currentLine.length() == 0) {
client.print("Finch St Temperature: ");
client.println(temperatureC);
break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
}
}
client.stop();
Serial.println("client disonnected");
}
{
digitalWrite(4,gate_solenoid);
unsigned long currentMillis = millis();
if((currentMillis - previousMillis) >= interval){
if (gate_solenoid){
interval = offTime;
}else{
interval = onTime;
}
gate_solenoid = !(gate_solenoid);
previousMillis = currentMillis;
}
{
}
}
}
No, none at all, I'm sorry to say, but you could alter your sketch to add some debug prints, so that you can see the times key events occur.
You can either print the value returned by the millis function, or use the serial monitor's own timestamp.
Also, strictly speaking, digitalWrite does not use booleans.
What does pinMode not work mean? The pinMode command only sets whether the pin is an input or an output, and when it is an output, the digitalWrite command sets a high or low potential.
Thanks for dumbing that down for me, I understand where I was going wrong now.
What I don't understand is why when I had only got pinMode (4,OUTPUT); in the code before I added the code for temperature feedback over Wifi, output 4 was triggering perfectly fine?