Hallo
We ervaren een probleem met het uitlezen van twee opto sonsoren welke alleen een 0 en 1 als output hebben.
Hieronder code en verder in engels. Hopelijk is dat geen probleem!?
My code
//for printf
#include <stdio.h>
const int S0Distance = 8; //pin attached to sensor that measures one complete turn
const int S1Distance = 11; //pin attached to sensor that measures one complete turn
//for printf
int my_putc( char c, FILE *t) {
Serial.write( c );
}
void setup()
{
pinMode(S0Distance,INPUT);
pinMode(S1Distance,INPUT);
Serial.begin(9600);
fdevopen( &my_putc, 0);
printf("test %i",10);
}
void loop()
{
bool done = false;
while (!done)
{
....
if (digitalRead(S0Distance) == HIGH)
{
printf("S0Distance high");
}
//a small delay didn't work out (1 to 10)
//delay(1);
if (digitalRead(S1Distance) == HIGH)
{
printf("S1Distance high");
}
}
}
The difficulty is that I don't get readings from both sensors at the same time. When I comment out one if statement the reading of the other sensor appear perfectly, but when using both if statements I only get readings from the first sensor (S0).
I'm sure I'm missing something here, since I don't expect that reading out 2 bytes at the same time would be too much for a arduino. All help and suggestions are welcome.