Add Whisker Indicator Lights

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. 

  • The Propeller Activity Board (original and WX version) uses built-in P26 and P27 LEDs for the LED circuits; see Blink a Light in the Simple Circuits tutorials before moving on.

  • Navigate to SimpleIDE > Learn > Examples > ActivityBot.
  • Open Test Whiskers With LEDs.side.
  • Click the Run with Terminal button. 
  • Try pressing each whisker.  The P26 light should turn on while the left whisker is pressed, and the P27 light should turn on while the right whisker is pressed.


How it Works

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


Try This

You can modify the program to make the lights blink when the whiskers are pressed like this:

  • Click the Save As Project button. 
  • Name the project Test Whiskers with Blinking LEDs.
  • Update the main function so that it matches the one above.
  • Click the Run with Terminal button. 
  • Press and hold each whisker to verify that it makes each light blink. 


Your Turn

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.  You can nest a for loop inside an if statement.