As you built the whisker circuits on your board, you connected two Propeller I/O pins to LEDs that are built into the circuit board. That means you can program the Propeller to send high/low signals to these I/O pins, which will turn the connected LEDs on/off.
Test Whiskers with LEDs.c is just the previous program with two if...else statements added. First, if(wL == 0) high(26); else low(26) does one of two things. If wL stores 0, it means the left whisker is pressed, so high(26) turns on the P26 LED. If wL stores 1, it means the whisker is not pressed. In that case, low(26) turns the LED off. The second line that was added is if(wR == 0) high(27); else low(27). It does the same job, except that it turns the P27 LED on/off depending on whether wR stores a 1 or 0.
/* Test Whiskers with LEDs.c Display whisker states in terminal. 1 = not pressed, 0 = pressed. */ #include "simpletools.h" // Include simpletools header int main() // main function { freqout(4, 2000, 3000); // Speaker tone: P4, 2 s, 3 kHz while(1) // Endless loop { int wL = input(7); // Left whisker -> wL variable int wR = input(8); // Right whisker -> wR variable if(wL == 0) high(26); else low(26); // Light for left whisker if(wR == 0) high(27); else low(27); // Light for right whisker print("%c", HOME); // Terminal cursor home (top-left) print("wL = %d wR = %d", wL, wR); // Display whisker variables pause(50); // Pause 50 ms before repeat } }
You can modify the program to make the lights blink when the whiskers are pressed like this:
Your challenge is to modify the Your Turn code to make it blink 10 times each time you press a whisker.
Hint: Review Counting Loops [1]. You can nest a for loop inside an if statement.
Links
[1] https://learn.parallax.com/propeller-c-start-simple/counting-loops