But, when I 'serial.monitor' what x is, after I have triggered the sensor, it remains as 1.
for some reason if I have an if statement that uses a 'digital input' then it won't change the value for x. For example if I just had if (x = 1) { x = 0; } that would work
yes. It will print out. perhaps there is another technique for what I want to do. I have 10 sensors, I want to save to an array[10] if at some point one of the sensors has or has not been triggered.
To elaborate, if all the sensors are off and one is triggered then It will run different code to if a sensor is activated but is not the first sensor.
I haven't tried this. I was just wondering if there is some special situation in Arduino that makes if statements with digitalread have some special conditions. I might simple my program and see if something else is causing the issue.
Yes, if you can provide a simplified example of your program which demonstrates the issue, I'm certain you'll get the help you need.
You should post code by using code-tags.
There are automatic functions for doing this in the Arduino-IDE.
Three steps:
1)press Ctrl-T for autoformatting your code
2)do a right click with the mouse and choose "copy for forum"
3)paste clipboard into write-window of a posting
void setup() { // initialize digital pin 13 as an output.
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(2, HIGH);
delay(1000); digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}