We replaced the flex sensor with a light sensor (also a variable resistor) for the input - making both the input and the output light. Now the critters could in principle talk to each other, but first we had to calibrate the values. This time we did it in a more sophisticated way - after establishing the approximate range of input values with the serial monitor, we mapped the values to the entire range of possible output values (0 to 255) to ensure maximum sensitivity. Given that counting can wrap we also constrained any input values that were outside of our approximated range to be 0 or 255.
|Calibrated values printed in the serial monitor - these are written to the output LED pin|
|The second critter's light is on when the first critter's light is off|
|Here every second critter's light is off|
|The finished critter with speaker (black) at back of breadboard and blue knob at front|
I decided to use the time since the program had been running (called with the millis function) to set up intervals - I have used a similar strategy previously in Processing. That is: if the time now is greater than the time that the previous tone began plus the previous tone duration plus the interval then begin the next tone.
|Timer using If statements and millis()|