-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e64be54
commit 8d21243
Showing
6 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,66 @@ | ||
// This is an example sketch to demonstrate embedded debugging | ||
// It is a modified blink sketch. It has four different modes: | ||
// off, on, slow blinking, fast blinking. You can cycle through these | ||
// modes by pressing a button, which is read using an interrupt. | ||
// Parallel to that, we prcess an ASCII input stream inverting the case of each | ||
// character before sending it out. | ||
// | ||
// In order to keep external components | ||
// at minimum, we use the builtin LED and a single button. | ||
// The blinking is implemented by using the "Timer/Counter0 Compare Match A" | ||
// interrupt. | ||
|
||
#include <ctype.h> | ||
|
||
#define LEDPIN LED_BUILTIN | ||
#define BUTTON 2 | ||
#define BUTTONGND 4 | ||
|
||
byte counter = 0; // the counter for blinking, it counts ms | ||
byte mode = 0; // the mode of the b linker | ||
unsigned long lastpress = 0; // when was button pressed last? | ||
|
||
const byte debounce_ms = 100; // the debounce time in ms | ||
|
||
void setup() { | ||
Serial.begin(19200); | ||
Serial.println(F("\nblinkmode V1.0.0")); | ||
pinMode(LEDPIN, OUTPUT); // initialize LEDPIN | ||
pinMode(BUTTONGND, OUTPUT); // make neighboring pin GND for the button | ||
pinMode(BUTTON, OUTPUT); // initialize button | ||
TIMSK0 |= _BV(OCIE0A); // enable Timer0 Compare Match A interrupt | ||
OCR0A = 0x80; // set interrupt time between two millis interrupts | ||
attachInterrupt(digitalPinToInterrupt(BUTTON), readButton, FALLING); | ||
} | ||
|
||
void loop() { | ||
char c; | ||
|
||
if (Serial.available()) { | ||
c = Serial.read(); | ||
if (isupper(c)) Serial.print(tolower(c)); | ||
else Serial.println(toupper(c)); | ||
|
||
} | ||
} | ||
|
||
void readButton() { | ||
if (lastpress + debounce_ms > millis()) | ||
return; | ||
lastpress = millis(); // remember time of last press for debouncing | ||
mode = (mode+1) % 4; // go to next mode | ||
} | ||
|
||
ISR(TIMER0_COMPA_vect) { // timer ISR | ||
counter++; // advance counter | ||
if (mode == 0) | ||
digitalWrite(LEDPIN, 0); // in mode 0, switch LED off | ||
if (mode == 1) | ||
digitalWrite(LEDPIN, 1); // in mode 1, switch LED on | ||
else if ((mode == 2 && counter > 500) || // in mode 2, toggle when going above 500 | ||
(counter > 100)) { // otherwise, when mode 3, after going above 100, | ||
digitalWrite(LEDPIN, // toggle LEDPIN | ||
!digitalRead(LEDPIN)); | ||
counter = 0; // reset counter to zero | ||
} | ||
} |