udamonic.com
  • Learn
    • What is a Scamp?
    • Order a Scamp
    • Getting Started
    • Learning Forth ... >
      • What is Forth?
      • Arithmetic
      • The Stack
      • Creating Words
      • Compilation Tricks
      • Comments
      • Characters and Strings
      • Constants, Variables and Values
      • Flow Control
      • Loops
      • Accessing Memory
      • Data Structures
      • Doubles, Triples and Quads
    • Extras... >
      • Starting up with turnkey
      • Formatting Text on Screen
      • Changing the Prompt
      • Delays and Tick Count
      • Processor Words
      • Temperature Sensor
      • Using the LED Array
    • Interfacing... >
      • Input/Output
      • Analog Input
      • Serial Communication
      • PWM
      • I2C Overview
      • I2C Commands
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Create
    • Adding LEDs
    • LED arc-welder effect
    • Measuring Temperature
    • Time Keeping
    • Model Train Control
    • FizzBuzz
    • Adding Extra GPIO
    • Adding a Low Side Switch
    • Adding an RTCC
  • Resources
  • Consult
  • About
  • Contact

Using with the LED Array
​

In addition to an amber status LED, the Scamp2 has a bank of 16 red LEDs that can be accessed using the leds word. Place the value to be output on the stack, then call leds. (Remember that using binary or hex numbers will make more sense.)
$5555 leds
will turn alternating LEDs on. 

​To turn all the LEDs off:
0 leds
Picture
The LED array can be useful for debugging in your code. For example, you can display the current stack entry to the LEDs:
dup leds
You can use the LEDs to display the current value from an analog input:
sample leds
This word will read the temperature sensor and use the LEDs as a thermometer scale, for temperatures between 20 and 35 degrees Celsius:
​: thermo
   begin 
      1          \ this gives a bit to turn a LED on
      temp drop  \ read temp and discard fraction
      20 -       \ make 20 degrees our baseline
      for        
        2 *      \ move the bits to the left for each degree
        1+       \ make it a bar graph
      next 
      leds       \ and display the bit
   key? until    \ loop until a key is pressed 
;
Alternatively, you can amuse family and pets by just playing with the LEDs.

​This word will randomly toggle the LEDs like an old mainframe or mini computer, and will blink the amber status LED as well. The loop terminates when a key is pressed, and then the LEDs are turned off. 

​: blinken
  begin
     random leds
     blink
  key? until
  0 leds
;
​
This word will make the LEDs shuffle back and forward:
​: shuffle
   begin
      $5555 leds
      100 ms
      $aaaa leds
      100 ms
   key? until
   0 leds
;
To make a single LED scan left and right:
: left
   #15 for
      #30 ms
      dup leds
      #2 * 
   next
;

: right
  #15 for
     #30 ms
     dup leds
     #2 u/
  next 
;

: cylon
  1
  begin
     left
     right
  key? until
  drop
  0 leds
;

Site powered by Weebly. Managed by Hostwinds
  • Learn
    • What is a Scamp?
    • Order a Scamp
    • Getting Started
    • Learning Forth ... >
      • What is Forth?
      • Arithmetic
      • The Stack
      • Creating Words
      • Compilation Tricks
      • Comments
      • Characters and Strings
      • Constants, Variables and Values
      • Flow Control
      • Loops
      • Accessing Memory
      • Data Structures
      • Doubles, Triples and Quads
    • Extras... >
      • Starting up with turnkey
      • Formatting Text on Screen
      • Changing the Prompt
      • Delays and Tick Count
      • Processor Words
      • Temperature Sensor
      • Using the LED Array
    • Interfacing... >
      • Input/Output
      • Analog Input
      • Serial Communication
      • PWM
      • I2C Overview
      • I2C Commands
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Create
    • Adding LEDs
    • LED arc-welder effect
    • Measuring Temperature
    • Time Keeping
    • Model Train Control
    • FizzBuzz
    • Adding Extra GPIO
    • Adding a Low Side Switch
    • Adding an RTCC
  • Resources
  • Consult
  • About
  • Contact