-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add required SyncLed Lib (origin no longer available on GitHub) - res…
…olves #1
- Loading branch information
Showing
38 changed files
with
1,359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
K 25 | ||
svn:wc:ra_dav:version-url | ||
V 29 | ||
/svn/!svn/ver/2/trunk/SyncLED | ||
END | ||
SyncLED.cpp | ||
K 25 | ||
svn:wc:ra_dav:version-url | ||
V 41 | ||
/svn/!svn/ver/2/trunk/SyncLED/SyncLED.cpp | ||
END | ||
SyncLED.h | ||
K 25 | ||
svn:wc:ra_dav:version-url | ||
V 39 | ||
/svn/!svn/ver/2/trunk/SyncLED/SyncLED.h | ||
END | ||
documentation.txt | ||
K 25 | ||
svn:wc:ra_dav:version-url | ||
V 47 | ||
/svn/!svn/ver/2/trunk/SyncLED/documentation.txt | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
10 | ||
|
||
dir | ||
2 | ||
http://arduino-library-syncled.googlecode.com/svn/trunk/SyncLED | ||
http://arduino-library-syncled.googlecode.com/svn | ||
|
||
|
||
|
||
2011-09-23T21:09:23.361560Z | ||
2 | ||
okachobi@gmail.com | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
62fe76ca-8c73-f804-774b-a94f392fa45f | ||
|
||
SyncLED.cpp | ||
file | ||
|
||
|
||
|
||
|
||
2014-10-08T12:13:49.000000Z | ||
1c1639663797388e8132ad5cb17afb33 | ||
2011-09-23T21:09:23.361560Z | ||
2 | ||
okachobi@gmail.com | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
2407 | ||
|
||
SyncLED.h | ||
file | ||
|
||
|
||
|
||
|
||
2014-10-08T12:13:49.000000Z | ||
d2a5517b9273b13a69db5c823cd9dcb1 | ||
2011-09-23T21:09:23.361560Z | ||
2 | ||
okachobi@gmail.com | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
1327 | ||
|
||
documentation.txt | ||
file | ||
|
||
|
||
|
||
|
||
2014-10-08T12:13:49.000000Z | ||
fa5a0a53de3bca88b83b4cb9f578992b | ||
2011-09-23T21:09:23.361560Z | ||
2 | ||
okachobi@gmail.com | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
220 | ||
|
||
examples | ||
dir | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "SyncLED.h" | ||
|
||
SyncLED::SyncLED(byte pin, byte initialState, boolean usePWM, unsigned long pwmMS):m_pin(pin),m_state(initialState), | ||
m_inPattern(false),m_lastChange(0L), m_usePWM(usePWM), m_pwmFadeMS(pwmMS) | ||
{ | ||
pinMode(pin, OUTPUT); | ||
digitalWrite(pin, initialState); | ||
m_state = initialState; | ||
} | ||
|
||
void SyncLED::blinkPattern(unsigned long pattern, unsigned long delay, byte pattern_length) | ||
{ | ||
setRate(delay); | ||
setPattern(pattern, pattern_length); | ||
} | ||
|
||
void SyncLED::setRate(unsigned long delay) | ||
{ | ||
m_delay = delay; | ||
} | ||
|
||
void SyncLED::setPattern(unsigned long pattern, byte pattern_length) | ||
{ | ||
m_pattern = pattern; | ||
m_patternLength = pattern_length; | ||
m_inPattern = true; | ||
m_patternPosition = 0; | ||
} | ||
|
||
// | ||
// Blink the LED x times | ||
// with a delay between blinks and a 4x off period between | ||
// series of blinks | ||
// | ||
void SyncLED::blinkPattern(uint8_t blinks, unsigned long delay) | ||
{ | ||
m_pattern = 0; | ||
for(int i=0; i < blinks;i++) { | ||
m_pattern |= (0b10000 << (i*2)); | ||
} | ||
m_patternLength = (blinks*2) + 4; | ||
m_delay = delay; | ||
m_inPattern = true; | ||
m_patternPosition = 3; | ||
} | ||
|
||
|
||
void SyncLED::On() | ||
{ | ||
m_state = HIGH; | ||
digitalWrite(m_pin, m_state); | ||
m_inPattern = false; | ||
m_lastChange = millis(); | ||
} | ||
|
||
void SyncLED::Off() | ||
{ | ||
m_state = LOW; | ||
digitalWrite(m_pin, m_state); | ||
m_inPattern = false; | ||
m_lastChange = millis(); | ||
} | ||
|
||
void SyncLED::resumePattern(boolean reset) | ||
{ | ||
if(reset) m_patternPosition = 0; | ||
m_inPattern = true; | ||
} | ||
|
||
boolean SyncLED::isOn() | ||
{ | ||
return( m_state == HIGH ); | ||
} | ||
|
||
void SyncLED::update() | ||
{ | ||
update(millis()); | ||
} | ||
|
||
void SyncLED::advanceState(unsigned long time_ms) | ||
{ | ||
m_patternPosition++; | ||
m_patternPosition %= m_patternLength; | ||
m_lastState = m_state; | ||
m_state = bitRead(m_pattern, m_patternPosition); | ||
m_lastChange = time_ms; | ||
} | ||
|
||
void SyncLED::update(unsigned long time_ms) | ||
{ | ||
if(!m_inPattern) return; | ||
|
||
unsigned long surpassed = time_ms - m_lastChange; | ||
|
||
if(!m_usePWM) { // Simple state changes... | ||
if(surpassed >= m_delay) { | ||
// Time to change LED state | ||
// Get the next bit out of the pattern | ||
advanceState(time_ms); | ||
|
||
// m_state ^= 1UL; | ||
digitalWrite( m_pin, m_state ); | ||
} | ||
} else { // Use PWM | ||
if(surpassed >= m_delay) { | ||
advanceState(time_ms); | ||
} | ||
|
||
// Progressive change | ||
// Map our current value and write it out - no | ||
if(m_lastState != m_state) | ||
analogWrite(m_pin, constrain( map( surpassed, 0, m_pwmFadeMS, (m_state?0:255), (m_state?255:0)), 0, 255)); | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef _SYNCLED_H_ | ||
#define _SYNCLED_H_ | ||
#include <WProgram.h> | ||
|
||
class SyncLED { | ||
|
||
public: | ||
SyncLED(byte pin, byte initialState = LOW, boolean usePWM = false, unsigned long pwmMS = 500); | ||
|
||
// Set the pattern (if desired) in binary ex: 0B1000010001 | ||
// Note that the max length is 32 bits... | ||
// Rate represents the delay between bits | ||
void blinkPattern(unsigned long pattern = 0B10101010101010101010101010101010, unsigned long delay = 1000, byte pattern_length = 32); | ||
void setRate(unsigned long delay); | ||
void setPattern(unsigned long pattern, byte pattern_length = 32); | ||
void blinkPattern(uint8_t blinks, unsigned long delay = 1000); | ||
|
||
// The following functions stop the current pattern | ||
// and set the LED state explicitly | ||
void On(); | ||
void Off(); | ||
|
||
// Resume pattern once stopped | ||
void resumePattern(boolean reset = false); | ||
|
||
// Return true if the light is currently on | ||
boolean isOn(); | ||
|
||
// Call one of these to update LED State | ||
void update(); | ||
void update(unsigned long time_ms); | ||
|
||
private: // methods | ||
void advanceState(unsigned long time_ms); | ||
|
||
private: // variables | ||
byte m_pin; | ||
unsigned long m_pattern; | ||
unsigned long m_delay; | ||
unsigned long m_lastChange; | ||
unsigned long m_pwmFadeMS; | ||
byte m_patternLength; | ||
byte m_inPattern; | ||
byte m_patternPosition; | ||
byte m_state; | ||
byte m_lastState; | ||
byte m_usePWM; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SyncLED library for Arduino | ||
|
||
Version 1.0 | ||
|
||
by Byron Guernsey | ||
|
||
contact: okachobi@gmail.com | ||
|
||
See the online documentation here: http://code.google.com/p/arduino-library-syncled/ | ||
See examples/ directory for simple examples | ||
|
Oops, something went wrong.