Monday, January 30, 2012

Maximite LED Control Example

Using MMIDE it is pretty easy to set up a large group of pins to drive LEDs. The “Scroll LEDs Applet” on the Direct I/O page of MMIDE groups all 20 lines into two groups of 10. The groups can be scrolled separately.

Behind the scenes the applet code sets all of the lines to be outputs. It then lights the LEDs one by one from left to right. Then the applet turns the LEDs off one by one from right to left.

Using the MMIDE Scroll LEDS Applet to test a group of LEDs.

Solderless breadboard setup for demonstration.

The ten LEDs are contained in a single package. Plugged into the solderless breadboard you can see that they connect on one side to pins 21-30 of J1 which means that they are controlled by MMBasic commands as pins 11-20. Current-limiting resistors (330 ohm) tie the LEDs to ground.

Setting those 10 lines to output and then turning each line on and off will turn each LED on and off.

60% power remaining on warp drive.

The Scroll LEDs Applet will light the LEDs from left to right when the “11-20” button is pressed.

Setting the applet aside, you can write a MMBasic program to control these LEDs, too. This example code will light and extinguish the LEDs randomly.

Using MMIDE to enter some code to control the LEDs

Code can be entered to the CGMMSTICK1 using the MMBasic page of MMIDE. The following code will flash the LEDs randomly.

10 For a = 11 To 20
20 SetPin a, 8
30 Next a
40 a = 11 + Fix(Rnd(0) * 10)
50 b = 11 + Fix(Rnd(0) * 10)
60 Pin(a) = 1
70 Pin(b) = 0
80 Pause 50
90 GoTo 40

MMBasic lines 10, 20, and 30 loop to set the I/O pins 11-20 to output.

MMBasic line 40 establishes a random pin to turn on. Rnd(0) generates a random value between 0 and 1 that is multiplied by 10 to get a random number between 1 and 10. “Fix” cleans up the number by removing the fraction. The number is offset by 11 to finally be a random number between 11 and 20 for pins 11-20.

MMBasic line 50 does the same thing for a random line to turn off.

60 and 70 turn off and on these lines respectively. MMBasic line 80 pauses for a twentieth of a second before line 90 forces the whole thing to repeat.

When run, the program turns the 10 LEDs on and off randomly.



Purchase a CGMMSTICK1

Download of Maximite Integrated Development Environment: MMIDE

No comments:

Post a Comment