Hello SparkFun Forum,
Working on doing some more complex things with LED displays.
Sometime ago built an electronic kit called Vellemen MK152.
http://www.vellemanusa.com/products/vie … &id=351406
The function of the kit could be described as a Wheel of Fortune.
It is 10-LED spinning wheel that uses a decade counter to increment from
one LED to another in a wheel configuration when a button is pushed.
The spinning speed gradually decreases until finally it stops and
one LED remains lit.
So from the ‘SIK Experiment Guide for Arduino - V3.2’
I swiped the module called ‘oneOnAtATime()’ from
Experiment 4: Driving Multiple LEDs. Then I got some code from
‘Experiment 5: Push Buttons’ (Sketch copied herewith below.)
Here are the changes I believe that are needed to make
‘oneOnAtATime()’ function like MK152:
-
Increase the number of LEDs from 8 to 10
-
Make the ‘oneOnAtATime()’ module begin with a push button
-
Make the ‘oneOnAtATime()’ module run for a range of time
between, say, 30 seconds and 60 seconds.
- Make the range of time that ‘oneOnAtATime()’ module runs
after the 30th second a random number of seconds between
1 and 30
-
Make the delayTime increase for the last ten LEDs.
-
Make the last LED stay on until the system is reset
or turned off.
Item 1 has been done by increasing the size of the array from 0 to 9
and adding pins 10 and 11.
Item 2 is accomplished by calling the ‘oneOnAtATime()’ module
from the If statement triggered by ‘button1State == LOW’
comparator.
The problem is the button must be held down for the
‘oneOnAtATime()’ module to continue to run. So trying to
figure out to how make pushing the button make the
LEDs continue to turn on and off without holding
the button down.
Then (I think) ‘oneOnAtATime()’ would make make the array blink
with the delayTime set to 150 ms (200 blinks at 150ms =
30,000 ms = 30 seconds. So
for(index = 0; index <= 9; index++)
But how is the if statement told that when the total number of milliseconds
gets to 30k to stop. Not asking for exact code just maybe a direction.
Maybe we could call this OneOnAtATimeFirst30k
I am beginning to think that OneOnAtATimeFirst30 should go
into void setup() area according to the idea that void setup()
happens once and void Loop() runs continuously
After OneOnAtATimeFirst30k a module (function?) is needed that not only increments
thru the pin assignments but creates a variable that is a random number
between 1 and 20. (The random number would have to be between 1 and 20
because at least ten numbers would be needed so there would always be at
least ten numbers to be used for the slow down at the end. So the best way to
do this would be to select a one of twenty random numbers between 1 and
20 and then and ten to that number so there could be a maximum of thirty but always
be at least ten.)
In Javascript (the language I know the best) this is done with
the Random() method:
var random_num
random_num = Math.floor((Math.random() * 20) + 1);
Then we would have a second module, say, OneOnAtATimeRandom30k.
Whatever method was used to count to thirty in OneOnAtATimeFirst30k
would be used in OneOnAtATimeRandom30k function, with the random number
substituted for 30.
The real killer would be in OneOnAtATimeRandom30k the last, ten
pin increments would have increasing larger delay times. If the
OneOnAtATimeRandom30k delayTimes are 150ms then the last ten increments
in OneOnAtATimeRandom30k would be
remaining pin increments 10 9 8 7 6 5 4 3 2 1
time in ms 160 170 180 190 200 210 220 230 240 250
So the question is: How to increment the pin assignment numbers and count the milliseconds?
I think the last LED would stay on until the button is pushed again
but I believe statements would have to be included in the setup
to return then pin assignment incrementer to zero and the millisecond
counter to zero.
Sorry for the length of this note but this is pretty complex stuff.
Finally is there someplace on SparfkFun or Arduino where the programming
part is exposed? I believe the language is C++ right? Maybe a search
on C++ tutorials would be productive.
Thanks
Allen Pitts
Dallas Texas
++++++++++++++++begin Wheel_of_Fortune++++++++++++++++++++++++
/*
Combine Multi LEDs and Pushbutton
*/
// To keep track of all the LED pins, we’ll use an “array”.
// 141230 add 2 LEDS to make total 10
int ledPins = {2,3,4,5,6,7,8,9,10,11};
const int ledPin = 13; // LED pin
// The first element of an array is index 0.
// We’ve put the value “2” in index 0, “3” in index 1, etc.
// The final index in the above array is 9, which contains
// the value “11”.
// We’re using the values in this array to specify the pin numbers
// to which tjhe ten LEDs are connected. LED 0 is connected to
// pin 2, LED 1 is connected to pin 3, etc.
void setup()
{
int index;
// Set up the pushbutton pins to be an input:
pinMode(button1Pin, INPUT);
// pinMode(button2Pin, INPUT); 141230 push Button 2 not needed
// Set up the LED pin to be an output:
pinMode(ledPin, OUTPUT);
void loop()
{
// creates button state variable
button1State = digitalRead(button1Pin);
if (((button1State == LOW) // if we’re pushing button 1
{
digitalWrite(ledPin, HIGH); // turn the LED on
oneOnAtATime(); // Turn on one LED at a time,
}
else
{
digitalWrite(ledPin, LOW); // turn the LED off
}
/*
oneOnAtATime()
This function will step through the LEDs,
lighting only one at at time.
*/
void oneOnAtATime()
{
int index;
int delayTime = 150; // milliseconds to pause between LEDs
// make this smaller for faster switching
// step through the LEDs, from 0 to 7
for(index = 0; index <= 9; index++)
{
digitalWrite(ledPins[index], HIGH); // turn LED on
delay(delayTime); // pause to slow down
digitalWrite(ledPins[index], LOW); // turn LED off
}
}
+++++++++++++++++++++++end of Wheel_of_Fortune+++++++++++++++++++