Editing
OpenHeartLib
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===== File Bill_OpenHeartMain.pde (complete) ===== <pre> //# NN=1 -- With delay(). //# NN=2 -- Looping over frames w/o delay(). //# NN=3 -- DOUBLE Looping with delay(). //# NN=4 -- Program DOUBLE looping over frames w/o delay(). //# NN=5 -- Simultaneous with tiny delay(). //# NN=6 -- Two flickering groups. //# NN=7 -- Purely random, one LED at a time. //# NN=8 -- Sequential concentric ring groups -- BEATING HEART! #define NN 8 /* Pick which section below to compile and execute. */ #include <OpenHeartLib.h> OpenHeart ht = OpenHeart(); // OpenHeart is a class. #if (NN == 1) //--- With delay(). 'g' is for "global" int gDelayTime = 100; byte gkmax = 27; // Number of Open Heart LED's void setup() { ht.setPinMap( 4, 5, 3, 2, 7, 6 ); } void loop() { for ( byte k=0 ; k<gkmax ; k++ ) { ht.turnOnLed (k); delay (gDelayTime); ht.alloff (); } } #elif (NN == 2) //--- Looping over frames w/o delay(). int gDelayTime = 100; byte gkmax = 27; byte gk = 0; unsigned long gLastTime = millis(); void setup() { ht.setPinMap( 4, 5, 3, 2, 7, 6 ); } void loop() { if ( gk < gkmax ) { if ( millis() < gLastTime + gDelayTime ) ht.turnOnLed (gk); else { ht.alloff(); gk++; gLastTime = millis(); } } else gk = 0; } #elif (NN == 3) //--- DOUBLE Looping with delay() int gDelayTime = 100; byte gjmax = 3; byte gkmax = 9; void setup() { ht.setPinMap( 4, 5, 3, 2, 7, 6 ); } void loop() { for ( byte j=0 ; j<gjmax ; j++ ) { for ( byte k=0 ; k<gkmax ; k++ ) { ht.turnOnLed( j*gkmax + k ); delay ( gDelayTime ); ht.alloff (); } } } #elif (NN == 4) //--- Program DOUBLE looping over frames w/o delay() int gDelayTime = 100; byte gjmax = 3; byte gkmax = 9; byte gj = 0; byte gk = 0; unsigned long gLastTime = millis(); void setup() { ht.setPinMap( 4, 5, 3, 2, 7, 6 ); gLastTime = millis(); // Not needed unless above executes too early. } void loop() { if ( gj < gjmax ) { if ( gk < gkmax ) { if ( millis() < gLastTime + gDelayTime ) ht.turnOnLed(gj*9 + gk); else { ht.alloff(); gk++; gLastTime = millis(); } } else { gk = 0; // Restart inner. gj++; // Increment outer. } } else gj = 0; // Restart outer. } #elif (NN == 5) //--- Simultaneous with tiny delay() int gDelayTime = 300; unsigned long gLastTime = millis(); //int kstart[] = { 0, 11, 23 }; // Top to bottom. //int kend [] = { 11, 23, 27 }; //int kstart[] = { 23, 11, 0 }; // Bottom to top. //int kend [] = { 27, 23, 11 }; int kstart[] = { 23, 4, 0 }; // Bot-to-top many lights in top group int kend [] = { 27, 23, 4 }; void setup() { ht.setPinMap( 4, 5, 3, 2, 7, 6 ); } void loop() { for ( byte j=0 ; j<3 ; j++ ) { while ( millis() < gLastTime + gDelayTime ) { for ( byte k=kstart[j] ; k<kend[j] ; k++ ) { ht.turnOnLed( k ); if ( j == 1 ) // Twinkle the middle LED group (ie, flash slower). delay( 5 ); ht.alloff(); } } gLastTime = millis(); } } #elif (NN == 6) //--- Two flickering groups. int gDelayTime = 1000; unsigned long gLastTime = millis(); int kstart[] = { 11, 0 }; // 16/11 ~ 1.5 int kend [] = { 27, 11 }; void setup() { ht.setPinMap( 4, 5, 3, 2, 7, 6 ); } void loop() { for ( byte j=0 ; j<2 ; j++ ) { while ( millis() < gLastTime + gDelayTime ) { for ( byte k=kstart[j] ; k<kend[j] ; k++ ) { ht.turnOnLed( k ); delay( j==0 ? 4 : 6 ); ht.alloff(); } } gLastTime = millis(); } } #elif (NN == 7) //--- Purely random, one LED at a time. int gDelayTime = 1; void setup() { Serial.begin(9600); ht.setPinMap( 4, 5, 3, 2, 7, 6 ); } void loop() { int k = random(27); ht.turnOnLed( k ); delay( gDelayTime ); ht.alloff(); delay( gDelayTime ); } #elif (NN == 8) //--- Sequential concentric ring groups -- BEATING HEART! int gDelayTime = 250; byte rings[][13] = { { 0, 1, 2, 3, 4, 10, 11, 17, 18, 22, 23, 25, 26}, { 5, 6, 7, 8, 9, 12, 16, 19, 21, 24, 99, 99, 99}, {13, 14, 15, 20, 99, 99, 99, 99, 99, 99, 99, 99, 99}, { 5, 6, 7, 8, 9, 12, 16, 19, 21, 24, 99, 99, 99} }; byte ringsN[ ] = { 13, 10, 4, 10 }; // Number of non-99 in each row above. byte Nrings = 4; byte ringNo = 0; unsigned long gLastTime = millis(); void setup() { ht.setPinMap( 4, 5, 3, 2, 7, 6 ); } void loop() { byte k; if ( ringNo < Nrings ) { k = 0; while ( millis() < gLastTime + gDelayTime ) { byte led = rings [ringNo][k]; if ( led != 99 ) { ht.turnOnLed( led ); delay( 10 * (ringsN[0]+0.0)/ringsN[ringNo] ); ht.alloff(); } k = (k+1) % ringsN[ringNo]; } ringNo++; gLastTime = millis(); } else ringNo = 0; } #endif //# Charlieplexing //# ++++++++++++++ //# From: http://www.instructables.com/id/Charlieplexing-LEDs--The-theory //# //# 0v/5v/open A -----[R]-----*-----*-----*-----* LED || A | B | C //# | | | | ====================== //# 1 V 2 ^ | | 1 1 0 XXX //# | | | | 2 0 1 XXX //# 0v/5v/open B -----[R]-----*-----* 5 V 6 ^ 3 XXX 1 0 //# | | | | 4 XXX 0 1 //# 3 V 4 ^ | | 5 1 XXX 0 //# | | | | 6 0 XXX 1 //# 0v/5v/open C -----[R]-----*-----*-----*-----* //# Open Heart LED Numbers //# [ 0 1 2 3 ] //# [ 4 5 6 7 8 9 10 ] //# [ 11 12 13 14 15 16 17 ] //# [ 18 19 20 21 22 ] //# [ 23 24 25 ] //# [ 26 ] </pre>
Summary:
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Noisebridge:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Request account
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Dig in!
Noisebridge
- Status: MOVED
- Donate
- ABOUT
- Accessibility
- Vision
- Blog
Manual
MANUAL
Visitors
Participation
Community Standards
Channels
Operations
Events
EVENTS
Guilds
GUILDS
- Meta
- Electronics
- Fabrication
- Games
- Music
- Library
- Neuro
- Philosophy
- Funding
- Art
- Crypto
- Documentation/Wiki
Wiki
Recent Changes
Random Page
Help
Categories
(Edit)
Tools
What links here
Related changes
Special pages
Page information