search
[last updated: 2016-07-31]
-----
//
// Program name: DSPBtest01
// edited for DigiSpark from PBtest
//
// Purpose:
// blink routine for onboard LED at setup
// blinks 1/sec heartbeat on board LED
// lights output LED when PB is pressed
//
// Edit History:
// rev. setupBlink_heartbeat: first rev
// rev. PBtest: added code to drive LED w/ PB
// rev. DSPBtest: edited for DigiSpark
// added PB & output LED
//
// Program operation/flow:
// blink on setup routine run at start & end of setup
// heartbeat done as first task in loop, millis-timed
// reads input from PB and lights LED accordingly
//
// Hardware configuration:
// P1 (for DS model A) reserved to drive onboard LED
// output LED on P4
// input PB on P5
// ------------------------
// ************** GLOBALS *******************
int redLED = 4;
int PB01 = 5;
int boardLED = 1;
unsigned long lastBeat = millis();
// ********* USER PREFERENCES SET HERE:
int numBlinks = 3; // not currently used ...
int prePause = 500;
int blinkOnShort = 100;
int blinkOnLong = 400;
int betweenBlinks = 160;
int postPause = 500;
// END setting user preferences
// ---------------- END globals -----------------
// ************** SETUP *******************
// line 40
void setup() {
pinMode(boardLED, OUTPUT);
// setup code goes here...
pinMode(redLED, OUTPUT);
pinMode(PB01, INPUT);
digitalWrite(PB01, HIGH);
// at end of setup: blink boardLED
blinkOnboard (prePause, 2, blinkOnLong, betweenBlinks, postPause);
blinkOnboard (prePause, 3, blinkOnShort, betweenBlinks, postPause);
}
// -------------- END setup --------------
// ************** LOOP *******************
void loop() {
// heartbeat
unsigned long currentTime = millis();
if (currentTime > (1000 + lastBeat))
{
heartBeat();
lastBeat = currentTime;
}
// end heartbeat code
// --------------------------------
// main loop here ...
if (digitalRead(PB01) == LOW) {
digitalWrite(redLED, HIGH); }
else {
digitalWrite(redLED, LOW);
}
}
// --------------- END loop ---------------
// **************** FUNCTION DEFS *****************
// list of function defs:
// blinkOnboard
// heartBeat
// --------------------------
void blinkOnboard (int prePause, int numBlinks, int blinkOn, int betweenBlinks, int postPause)
{
// blinks onboard LED-13
// takes parameters: pre-pause; # blinks; blinkOn duration; betweenBlink pause duration; post-pause
delay(prePause);
for (int n = 0; n < numBlinks; n++)
{
digitalWrite(boardLED, HIGH);
//digitalWrite(redLED, HIGH);
delay(blinkOn);
digitalWrite(boardLED, LOW);
//digitalWrite(redLED, LOW);
delay(betweenBlinks);
}
delay(postPause);
} // END blinkOnboard
// ----------------------
void heartBeat ()
{
blinkOnboard(1, 1, 60, 1, 1);
int lastBeat = millis();
} // END heartBeat
// ----------------
// --------------- END function defs ------------
// --------------- END program ------------------
.
.
.
eof