I have an esp 12-e wifi node and trying to send a value of 1(or any number) if my condition is met or a 0(or any number) if another from my 12-e to my unos analog in. How can i do this?
i was thinking on the esp have:
val = 1
digitalWrite(10, val)
where 10 is the GPIO pin and for it to write the value 1.
Then for the uno to have;
val2 = analogRead(0);
Serial.println(val);
where 0 is the analog pin 0 and reads the value coming in from the esp then save it in the variable val2 but this is not working
Delta_G:
digitalWrite(10, val)
digitalWrite only writes a HIGH voltage or a LOW voltage. Not a number. If the only thing you want is 0 or 1, then you can choose to interpret HIGH as 1 and LOW as 0 or vice-versa.
val2 = analogRead(0);
You created this signal with digitalWrite. So it is digital. It's HIGH or LOW. analogRead is for reading analog signals, any voltage between 0 and 5. Again, if you only want 0 or 1 then you could do a digitalRead here and interpret a LOW as 0 and a HIGH as 1 or vice versa.
If you really want to send actual numbers, then you can't do that with a GPIO pin like this. You need to use serial or I2C or SPI or some other communication protocol. Google those to learn more about them.
So on the esp, could i just write digitalWrite(10, HIGH) to interpret the 0 or 1? What code should i write then on the uno to interpret this? If it makes it easier, i was going to make it a boolean variable to like if the input read was HIGH, variable = true. If input LOW, variable = false
Delta_G:
See, you already know how to do it.
if(digitalRead(somePin) == HIGH){
myBoolean = true;
}
else {
myBoolean = false;
}
Alright I just implimented this in the loop method and it just iterates from true and false and not just one
Delta_G:
How exactly do you propose I go about finding the bug in code I can't see?
Sorry. I was just trying to get bare minimum code. But here it is: ----------------------For the UNO----------------------int input = 13;bo - Pastebin.com
Delta_G:
It explains how to post code here and how to get help with your issue.
----------------------
For the UNO
----------------------
int input = 13;
bool status;
void setup()
{
pinMode(input, INPUT);
Serial.begin(9600);
}
void loop(){
if(digitalRead(input) == HIGH){
status = true;
}
if(digitalRead(input) == LOW){
status = false;
}
Serial.println(status);
}
----------------------
For the ESP
----------------------
int outputPin = 10;
void setup(){
pinMode(outputPin, OUTPUT);
}
//other code yadda yadda
void turnOn(String deviceId){
if(deviceID == DEVICE1){
digitalWrite(outputPin, HIGH);
}
}
void turnOff(String deviceId){
if(deviceID == DEVICE1){
digitalWrite(outputPin, LOW);
}
}
//now making an LED turn on and off with digitalWrite will work fine. So the yadda yadda code works. Its just when to turn the "device" on or off to carry out the HIGH and LOW will not pass and gives HIGH/LOW constantly