What am I doing wrong in ESP8266 code?

I'm having trouble understading what I'm doing wrong here. I'm just doing some simple experiments with an 8266 project and am struggling with what is happening.
In the attached sketch I have 2 push buttons connecting 3v to D7(GPIO13) and D8(GPIO15) with both tied low with 4k7 resitors. Pressing button on D7 should turn on output D6(GPIO12) and Button D8 should turn it off again. It doesn't work, so I added the serial.prinlnt lines to debug. When the program runs the buttons do nothing and the serial output reports both GPIO15 and GPIO13 High all the time. Any ideas? Many thanks

int output12 = 12;
int input13 = 13;
int input15 = 15;


void setup() {

  Serial.begin(115200);

  pinMode(13, INPUT);
  pinMode(15, INPUT);
  pinMode(12, OUTPUT);

  digitalWrite(output12, LOW);
}

void loop() {
  if (input13 = 1) digitalWrite(output12, HIGH);
  if (input15 = 1) digitalWrite(output12, LOW);
  if (input13 = 1) Serial.println("Input 13 = High");
  if (input15 = 1) Serial.println("Input 15 = High");
}

you don't appear to actually read pin 13 try

void loop() {
  if (digitalRead(13) == 1) digitalWrite(output12, HIGH);

also note the use of operator == (test for equality) not = assignment as in your code

Ah, thank you, it had to be something simple. I think I'm getting too old for this :wink:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.