Battery-powered models - 20
45
45. Examples window.
used for room lights in my model structures. It can turn back-
ground buildings from lifeless shadows into hives of activity.
Here is the sketch:
#define numleds
16 byte ledpins [ ] =
{ 0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 } ;
void setup( ) {
for ( int i=1; i <= numleds; i++ ) {
pinMode ( ledpins [ i ], OUTPUT) ;
digitalWrite ( ledpins [ i ] , HIGH) ;
}
void loop ( ) {
digitalWrite ( ledpins [ random ( 0, numleds+1 ) ], lightsw ( ) ) ;
delay ( 900 ) ;
}
boolean lightsw ( ) {
if ( random (0,100) > 40 ) return LOW ;
else return HIGH ;
}
Copy, paste , and save it as a text file, but name it with a “.ino” suf-
fix like “building.ino”
Then open the file with the Arduino IDE and load it into your Pro
Mini. You can also copy and paste the text directly into the Arduino
editor window. (See this issue’s subscriber downloads for the code.)
Now let’s set up the Pro Mini Board. Since this will be part of a
freestanding model, we need to power the board independently.
A cheap and easy alternative is a “wall wart” 5 Volt DC power
adapter commonly available. I cut off the connector at the end.
Strip the two wires exposing the bare wires, not allowing them
to touch.
MRH-Nov 2014