forked from rabidaudio/synthesizer
-
Notifications
You must be signed in to change notification settings - Fork 0
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
e5da67d
commit d47b305
Showing
8 changed files
with
260 additions
and
204 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
// A push-button toggle switch. Supports debouncing. | ||
|
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
// A continuous rotary switch with evenly-valued resistors between each | ||
|
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 |
---|---|---|
@@ -1,60 +1,83 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
#define CHAR_BLANK 0b00000000 | ||
#define CHAR_MINUS 0b00000010 | ||
#define CHAR_UNDERSCORE 0b00001000 | ||
|
||
// TODO: would switch be faster than | ||
// array index? | ||
const uint8_t LETTERS[] = { | ||
// ABCDEGF | ||
0b01111101, | ||
0b00110000, | ||
0b01101110, | ||
0b01111010, | ||
0b00110011, | ||
0b01011011, | ||
0b01011111, | ||
0b01110000, | ||
0b01111111, | ||
0b01111011, | ||
//_ABCDEGF | ||
0b01111101, | ||
0b00110000, | ||
0b01101110, | ||
0b01111010, | ||
0b00110011, | ||
0b01011011, | ||
0b01011111, | ||
0b01110000, | ||
0b01111111, | ||
0b01111011, | ||
}; | ||
|
||
class SevenSegment { | ||
private: | ||
uint8_t _controlPin; | ||
volatile uint8_t* _segmentPort; | ||
|
||
public: | ||
// NOTE: its up to the caller to set the segmentPort to an | ||
// output since we don't know which registers to use | ||
void begin(uint8_t controlPin, volatile uint8_t* segmentPort) { | ||
_controlPin = controlPin; | ||
_segmentPort = segmentPort; | ||
pinMode(controlPin, OUTPUT); | ||
turnOff(); | ||
} | ||
// Addresses a common-cathode 7-segment display without a | ||
// decimal. | ||
// Assumes ABCDEGF segments are connected to pins 0-6 of | ||
// a AVR port for faster addressing. | ||
// The control pin should be connected to the common cathode. | ||
// It is pulled low to turn on the LEDs. | ||
class SevenSegment | ||
{ | ||
private: | ||
uint8_t _controlPin; | ||
volatile uint8_t *_segmentPort; | ||
|
||
void turnOff() { | ||
digitalWrite(_controlPin, HIGH); | ||
} | ||
public: | ||
void begin(uint8_t portNumber, uint8_t controlPin) | ||
{ | ||
_controlPin = controlPin; | ||
_segmentPort = portOutputRegister(portNumber); | ||
pinMode(controlPin, OUTPUT); | ||
volatile uint8_t *portModeRegister = portModeRegister(portNumber); | ||
*portModeRegister = 0x7F; | ||
turnOff(); | ||
} | ||
|
||
void turnOn() { | ||
digitalWrite(_controlPin, LOW); | ||
} | ||
void turnOff() | ||
{ | ||
digitalWrite(_controlPin, HIGH); | ||
} | ||
|
||
bool display(char c) { | ||
if (c >= '0' && c <= '9') { | ||
*_segmentPort = LETTERS[c - '0']; | ||
return true; | ||
} | ||
if (c == ' ') { | ||
*_segmentPort = CHAR_BLANK; | ||
return true; | ||
} | ||
if (c == '-') { | ||
*_segmentPort = CHAR_MINUS; | ||
return true; | ||
} | ||
// unsupported char | ||
return false; | ||
void turnOn() | ||
{ | ||
digitalWrite(_controlPin, LOW); | ||
} | ||
|
||
bool display(char c) | ||
{ | ||
if (c >= '0' && c <= '9') | ||
{ | ||
*_segmentPort = LETTERS[c - '0']; | ||
return true; | ||
} | ||
if (c == ' ') | ||
{ | ||
*_segmentPort = CHAR_BLANK; | ||
return true; | ||
} | ||
if (c == '-') | ||
{ | ||
*_segmentPort = CHAR_MINUS; | ||
return true; | ||
} | ||
if (c == '_') | ||
{ | ||
*_segmentPort = CHAR_UNDERSCORE; | ||
return true; | ||
} | ||
// unsupported char | ||
return false; | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
#define NO_TEMPO 0 | ||
|
Oops, something went wrong.