init
This commit is contained in:
parent
028d928f9b
commit
b72d058b97
3 changed files with 2072 additions and 0 deletions
298
pocketpsithemius.ino
Normal file
298
pocketpsithemius.ino
Normal file
|
|
@ -0,0 +1,298 @@
|
|||
/*MIT License
|
||||
|
||||
Copyright (c) 2020 Sublunar Psionics
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
Special Thanks to Slavko Andrejevic for providing the main framework of this
|
||||
firmware and for technical support.
|
||||
|
||||
*/
|
||||
|
||||
#define btnA 9 //PB0 / Button A:
|
||||
#define btnB 8 //PB1 / Button B:
|
||||
#define btnC 13 //PA7 / Button C:
|
||||
#define led_R 12 //PA6 / RED LED
|
||||
#define led_G 14 //PA3 / GREEN LED
|
||||
#define led_B 1 //PA1 / BLUE LED
|
||||
#define uv_LED 6 //PB3 / UV LED
|
||||
#define OPAMP 3 //PB6 / turns on the Op Amp circuit
|
||||
#define ON HIGH
|
||||
#define OFF LOW
|
||||
|
||||
//---- BUTTONS ----
|
||||
byte counterA = 0; //count push btnA:
|
||||
byte counterB = 0; //count push btnB:
|
||||
byte counterC = 0; //count push btnC:
|
||||
bool enabled_btnAC = true; //Button A + C enabled or not
|
||||
bool enabled_btnB = true; //Button B enabled or not
|
||||
static bool last_btnA = false; //Previous state of button A
|
||||
static bool last_btnB = false; //Previous state of button B
|
||||
static bool last_btnC = false; //Previous state of button C
|
||||
|
||||
//---- LEDS ----
|
||||
bool enabled_LED = false; //turn on a tricolor LED
|
||||
bool was_on_LED = false; //was LED on?
|
||||
bool usePWM = false; //use softPWM for more nuanced colors
|
||||
void offLeds() {
|
||||
analogWrite(led_R, 255);
|
||||
analogWrite(led_B, 255);
|
||||
analogWrite(led_G, 255);
|
||||
}
|
||||
|
||||
//---- TIMER ----
|
||||
bool countDelay = false; //are we counting ticks to time out the UV LEDs?
|
||||
static uint32_t delayCount = 0;
|
||||
long lastDebounceTime = 0; // the last time the output pin was toggled
|
||||
long debounceDelay = 50; // the debounce time; increase if the output flickers
|
||||
|
||||
//---- COLOR ----
|
||||
struct COLOR { //Creating structure for colors
|
||||
byte r;
|
||||
byte g;
|
||||
byte b;
|
||||
};
|
||||
COLOR selectedColor = { 0 , 0 , 0 };
|
||||
|
||||
void setColor(COLOR paint, bool full = true) {
|
||||
//tricolor LED color
|
||||
selectedColor = paint;
|
||||
selectedColor.r = paint.r;
|
||||
selectedColor.b = paint.b;
|
||||
selectedColor.g = paint.g;
|
||||
//paint contains r g b value for pwm on pins
|
||||
showColor();
|
||||
}
|
||||
|
||||
void showColor() {
|
||||
if (enabled_LED == true) {
|
||||
softPWM(led_R, selectedColor.r, 1);
|
||||
softPWM(led_B, selectedColor.b, 1);
|
||||
softPWM(led_G, selectedColor.g, 1);
|
||||
} else {
|
||||
offLeds();
|
||||
}
|
||||
}
|
||||
|
||||
//---- PLANETARY COLORS ----
|
||||
COLOR white = { 255 , 255 , 255 }; //Moon correspondence
|
||||
COLOR orange = { 255 , 128 , 0 }; //Mercury correspondence
|
||||
COLOR green = { 0 , 255 , 0 }; //Venus correspondence
|
||||
COLOR yellow = { 255 , 255 , 0 }; //Sol correspondence
|
||||
COLOR red = { 255 , 0 , 0 }; //Mars correspondence
|
||||
COLOR blue = { 0 , 128 , 255 }; //Jupiter correspondence
|
||||
COLOR purple = { 128 , 0 , 128 }; //Jupiter/Moon correspondence
|
||||
COLOR indigo = { 111 , 0 , 255 }; //Saturn correspondence
|
||||
COLOR grey = { 40 , 40 , 40 }; //Saturn correspondence
|
||||
|
||||
//---- DEVICE SETUP ----
|
||||
void setup() {
|
||||
|
||||
//Buttons
|
||||
pinMode(btnA, INPUT);
|
||||
pinMode(btnB, INPUT);
|
||||
pinMode(btnC, INPUT);
|
||||
|
||||
//LEDS
|
||||
pinMode(led_B, OUTPUT);
|
||||
pinMode(led_G, OUTPUT);
|
||||
pinMode(led_R, OUTPUT);
|
||||
offLeds();
|
||||
|
||||
//UV LED
|
||||
pinMode(uv_LED, OUTPUT);
|
||||
digitalWrite(uv_LED, OFF);
|
||||
|
||||
// OP AMP
|
||||
pinMode(OPAMP, OUTPUT);
|
||||
digitalWrite(OPAMP, OFF);
|
||||
}
|
||||
|
||||
//---- DEVICE LOOP ----
|
||||
void loop() {
|
||||
|
||||
// Detect and debounce button presses
|
||||
if ( (millis() - lastDebounceTime) > debounceDelay) {
|
||||
|
||||
//Button A:
|
||||
bool pressed_btnA = !digitalRead(btnA);
|
||||
if (pressed_btnA != last_btnA ) {
|
||||
if (pressed_btnA == true) {
|
||||
counterA++;
|
||||
if (counterA > 10)counterA = 1;
|
||||
pressButton_A();
|
||||
}
|
||||
last_btnA = pressed_btnA;
|
||||
}
|
||||
|
||||
//Button B:
|
||||
bool pressed_btnB = !digitalRead(btnB);
|
||||
if (pressed_btnB != last_btnB ) {
|
||||
if (pressed_btnB == true) {
|
||||
counterB++;
|
||||
if (counterB > 2)counterB = 1;
|
||||
pressButton_B();
|
||||
}
|
||||
last_btnB = pressed_btnB;
|
||||
}
|
||||
|
||||
//Button C:
|
||||
bool pressed_btnC = !digitalRead(btnC);
|
||||
if (pressed_btnC != last_btnC ) {
|
||||
if (pressed_btnC == true) {
|
||||
counterC++;
|
||||
if (counterC > 2)counterC = 1;
|
||||
pressButton_C();
|
||||
}
|
||||
last_btnC = pressed_btnC;
|
||||
}
|
||||
lastDebounceTime = millis(); //set the current time
|
||||
}
|
||||
|
||||
showColor();
|
||||
|
||||
//Counts up and turns UV LED off after 1min
|
||||
if (countDelay == true) {
|
||||
delayCount++;
|
||||
counterB = 1;
|
||||
}
|
||||
else delayCount = 0;
|
||||
if (delayCount > 1200000) {
|
||||
//Turn the UV LED off
|
||||
digitalWrite(uv_LED, LOW);
|
||||
countDelay = false;
|
||||
//Reenable all buttons
|
||||
enabled_btnAC = true;
|
||||
//LED Status back to before Button B was pushed
|
||||
enabled_LED = was_on_LED;
|
||||
}
|
||||
}
|
||||
|
||||
//---- BUTTON STATE MACHINE FUNCTIONS
|
||||
//Button A:
|
||||
void pressButton_A() {
|
||||
if (enabled_btnAC == false) {
|
||||
counterA = 0;
|
||||
return;//Chek if button is disabled
|
||||
}
|
||||
switch (counterA) {
|
||||
case 1:
|
||||
enabled_LED = true;
|
||||
setColor(white, true);
|
||||
break;
|
||||
case 2:
|
||||
usePWM = true;
|
||||
setColor(orange, true);
|
||||
break;
|
||||
case 3:
|
||||
usePWM = false;
|
||||
setColor(green, true);
|
||||
break;
|
||||
case 4:
|
||||
setColor(yellow, true);
|
||||
break;
|
||||
case 5:
|
||||
setColor(red, true);
|
||||
break;
|
||||
case 6:
|
||||
setColor(blue, true);
|
||||
break;
|
||||
case 7:
|
||||
usePWM = true;
|
||||
setColor(purple, true);
|
||||
break;
|
||||
case 8:
|
||||
setColor(indigo, true);
|
||||
break;
|
||||
case 9:
|
||||
setColor(grey, true);
|
||||
break;
|
||||
case 10:
|
||||
enabled_LED = false;
|
||||
counterA = 0;//TURN OFF
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Button B:
|
||||
void pressButton_B() {
|
||||
if (enabled_btnB == false) {
|
||||
counterB = 0;
|
||||
return;
|
||||
}
|
||||
if (counterB == 1) { //1st press:
|
||||
//was color LED on when button was pushed?
|
||||
was_on_LED = enabled_LED;
|
||||
//Disable LED and buttons A and C
|
||||
enabled_LED = false;
|
||||
counterA = 0;
|
||||
counterC = 0;
|
||||
enabled_btnAC = false;
|
||||
enabled_btnB == false;
|
||||
//Turn off Op-Amp circuit
|
||||
digitalWrite(OPAMP, OFF);
|
||||
enabled_btnB == true;
|
||||
digitalWrite(uv_LED, ON);
|
||||
countDelay = true; // turn on delay counter in loop()
|
||||
}
|
||||
if (counterB == 2) { //2nd press:
|
||||
if (digitalRead(uv_LED) == ON) {
|
||||
//Turn UV LED off
|
||||
digitalWrite(uv_LED, OFF);
|
||||
}
|
||||
//Re-enable all buttons
|
||||
enabled_btnAC = true;
|
||||
enabled_btnB = true;
|
||||
//LED Status back to before Button B was pushed
|
||||
enabled_LED = was_on_LED;
|
||||
//reset delay counter
|
||||
countDelay = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Button C:
|
||||
void pressButton_C() {
|
||||
if (enabled_btnAC == false) {
|
||||
counterC = 0;
|
||||
return;
|
||||
}
|
||||
if (counterC == 1) { //1st press:
|
||||
digitalWrite(OPAMP, ON);
|
||||
}
|
||||
if (counterC == 2) { //2nd press:
|
||||
digitalWrite(OPAMP, OFF);
|
||||
}
|
||||
}
|
||||
|
||||
//---- SOFTWARE PWM ----
|
||||
// software PWM function that fakes analog output
|
||||
void softPWM(byte pin, byte freq, byte sp) {
|
||||
byte delay1 = 255 - freq;
|
||||
if (usePWM == true) {
|
||||
while (sp > 0) {
|
||||
digitalWrite(pin, LOW); //on
|
||||
delayMicroseconds(freq);
|
||||
digitalWrite(pin, HIGH); //off
|
||||
delayMicroseconds(delay1);
|
||||
sp--;
|
||||
}
|
||||
} else {
|
||||
analogWrite(pin, 255 - freq);
|
||||
}
|
||||
}
|
||||
130
pocketpsithemius.ino.hex
Normal file
130
pocketpsithemius.ino.hex
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
:1000000033C04BC04AC049C048C047C03FC245C0CA
|
||||
:1000100044C043C042C041C040C03FC03EC03DC0DC
|
||||
:100020003CC03BC03AC000000000050004000300D3
|
||||
:10003000000000000000010204402010080402013A
|
||||
:100040001020408008800101010202020202020227
|
||||
:1000500001010101010200003900360000003B00EF
|
||||
:10006000380000003A00370011241FBECFEDCDBF8D
|
||||
:1000700010E0A0E6B0E0EEEDF7E002C005900D92D2
|
||||
:10008000A238B107D9F720E0A2E8B0E001C01D9284
|
||||
:10009000A03AB207E1F79BD3A0C3B2CF6FEF70E0F5
|
||||
:1000A0008CE064D26FEF70E081E060D26FEF70E0BF
|
||||
:1000B0008EE05CC260E089E0AFD260E088E0ACD264
|
||||
:1000C00060E08DE0A9D261E081E0A6D261E08EE03F
|
||||
:1000D000A3D261E08CE0A0D2E1DF61E086E09CD2B7
|
||||
:1000E00060E086E0EDD261E083E096D260E083E0FC
|
||||
:1000F000E7C2CF9380917F00811104C010929500D8
|
||||
:10010000CF910895C0919500C130A1F480919000E5
|
||||
:1001100080938F001092900010929600109294009D
|
||||
:100120001092800060E083E0CBD261E086E0C8D22C
|
||||
:10013000C0938D0080919500823011F786E007D33F
|
||||
:10014000019719F460E086E0BBD281E080938000E3
|
||||
:1001500080937F0080918F008093900010928D009B
|
||||
:10016000CFCF80918000811103C010929400089538
|
||||
:1001700080919400813019F461E083E0A1D28091F4
|
||||
:100180009400823019F460E083E09AC20895EF92FF
|
||||
:10019000FF920F931F93CF93DF93182F042F80911B
|
||||
:1001A0008E00882399F0E62EF12C6095C62FD0E0C2
|
||||
:1001B0000023D1F060E0812F83D2C701BDD161E07F
|
||||
:1001C000812F7ED2CE01B8D10150F2CF8FEF90E0D7
|
||||
:1001D0009C01261B3109B901812FDF91CF911F911D
|
||||
:1001E0000F91FF90EF90C2C1DF91CF911F910F91BE
|
||||
:1001F000FF90EF90089580919000882379F041E07E
|
||||
:10020000609182008CE0C3DF41E06091840081E076
|
||||
:10021000BEDF41E0609183008EE0B9CF3FCF6093B5
|
||||
:1002200082007093830080938400E5CF80918000EA
|
||||
:10023000811103C0109296000895E0919600E1505C
|
||||
:10024000EA30D0F7F0E0EA5DFE4F099409C012C031
|
||||
:100250001BC023C029C02FC035C03EC044C04AC007
|
||||
:1002600081E0809390006091780070917900809196
|
||||
:100270007A00D5CF81E080938E00609175007091F7
|
||||
:10028000760080917700F5CF10928E006091720019
|
||||
:100290007091730080917400ECCF60916F00709149
|
||||
:1002A000700080917100E5CF60916C0070916D00DD
|
||||
:1002B00080916E00DECF6091690070916A0080913C
|
||||
:1002C0006B00D7CF81E080938E00609166007091C3
|
||||
:1002D000670080916800CDCF6091630070916400E9
|
||||
:1002E00080916500C6CF609160007091610080913F
|
||||
:1002F0006200BFCF109290009DCF0F931F93CF93BA
|
||||
:100300000FD10091850010918600209187003091D7
|
||||
:100310008800601B710B820B930B00917B00109186
|
||||
:100320007C0020917D0030917E000617170728077A
|
||||
:10033000390708F04EC089E00AD2C1E0009709F001
|
||||
:10034000C0E0209193002C1769F0892B49F480912B
|
||||
:1003500096008F5F8B3008F074C08093960066DF44
|
||||
:10036000C093930088E0F3D1C1E0009709F0C0E0AA
|
||||
:10037000209192002C1769F0892B49F48091950007
|
||||
:100380008F5F833008F05FC080939500B2DEC0932A
|
||||
:1003900092008DE0DCD1C1E0009709F0C0E020912F
|
||||
:1003A00091002C1769F0892B49F4809194008F5F9C
|
||||
:1003B000833008F04AC080939400D3DEC09391004C
|
||||
:1003C000AFD06093850070938600809387009093F0
|
||||
:1003D000880011DF80918D008823C9F18091890008
|
||||
:1003E00090918A00A0918B00B0918C000196A11D84
|
||||
:1003F000B11D8093890090938A00A0938B00B093E5
|
||||
:100400008C0081E0809395008091890090918A0012
|
||||
:10041000A0918B00B0918C0081389F44A241B1051E
|
||||
:1004200060F060E086E04CD110928D0081E0809316
|
||||
:10043000800080918F0080939000CF911F910F9149
|
||||
:10044000089581E08ACF81E09FCF81E0B4CF109200
|
||||
:10045000890010928A0010928B0010928C00D4CFE9
|
||||
:100460008FB5807F8FBD80B7826080BF80B781608D
|
||||
:1004700080BF87B5816087BD86B58D7F86BD86B517
|
||||
:10048000816086BD8FB587608FBD08951F920F92E2
|
||||
:100490000FB60F9211242F933F938F939F93AF9397
|
||||
:1004A000BF938091980090919900A0919A00B0918B
|
||||
:1004B0009B003091970023E0230F2D3768F126E849
|
||||
:1004C000230F0296A11DB11D2093970080939800E1
|
||||
:1004D00090939900A0939A00B0939B0080919C0008
|
||||
:1004E00090919D00A0919E00B0919F000196A11D4A
|
||||
:1004F000B11D80939C0090939D00A0939E00B093AB
|
||||
:100500009F00BF91AF919F918F913F912F910F903D
|
||||
:100510000FBE0F901F9018950196A11DB11DD4CF4D
|
||||
:100520002FB7F894609198007091990080919A008B
|
||||
:1005300090919B002FBF08958230910538F0880F6D
|
||||
:10054000991F880F991F05970197F1F708957894DF
|
||||
:1005500083B7887F836083BF789489B7826089BFBF
|
||||
:100560007FDF86B1876886B9379A08951F93CF9346
|
||||
:10057000DF93182FEB0161E04FD01C161D0634F0FD
|
||||
:1005800060E0812FDF91CF911F919AC0CF3FD105BD
|
||||
:1005900014F061E0F6CFE12FF0E0EA5DFF4FE49167
|
||||
:1005A000E33059F487B58F7787BD87B5806487BD01
|
||||
:1005B000CDBDDF91CF911F910895E43041F487B50F
|
||||
:1005C0008F7D87BD87B5806187BDCCBDF2CFE5301B
|
||||
:1005D00041F487B5877F87BD87B5846087BDCABD75
|
||||
:1005E000E8CFC038D105ACF6CBCF833021F480B74B
|
||||
:1005F0008F7780BF0895843039F487B58F7D87BDAC
|
||||
:1006000087B58F7E87BD08958530E9F787B5877FE9
|
||||
:1006100087BD87B58B7FF6CFCF93DF9387FF0CC065
|
||||
:100620008F77833048F0282F30E0A90143505109DB
|
||||
:100630004430510540F5895F90E0FC01EA5CFF4FD2
|
||||
:1006400024918A5B9F4FFC0184918823C9F090E03C
|
||||
:10065000880F991FFC01EE59FF4FA591B491FC0141
|
||||
:10066000E45AFF4FC591D491611117C09FB7F89418
|
||||
:100670008C91209582238C938881282328839FBF87
|
||||
:10068000DF91CF910895275031099CE0981B892F65
|
||||
:100690002330310588F28FEFCFCF623051F49FB70E
|
||||
:1006A000F8943C91822F809583238C93E8812E2BA4
|
||||
:1006B000E5CF8FB7F894EC912E2B2C938FBFE0CF22
|
||||
:1006C0001F93CF93DF93162F87FF0CC08F77833054
|
||||
:1006D00048F0282F30E0A90143505109443051051A
|
||||
:1006E00040F5895F282F30E0F901EA5DFF4F8491E2
|
||||
:1006F000F901EA5CFF4FD491F901EA5BFF4FC49125
|
||||
:10070000CC2399F0811171DFEC2FF0E0EE0FFF1F89
|
||||
:10071000E45AFF4FA591B4918FB7111114C0F8940A
|
||||
:10072000EC91D095DE23DC938FBFDF91CF911F91A9
|
||||
:100730000895275031099CE0981B892F23303105FB
|
||||
:1007400088F28FEFCFCFF894EC91DE2BECCFCF93E4
|
||||
:10075000DF9387FF0CC08F77833048F0282F30E07D
|
||||
:10076000A901435051094430510520F5895F282FD4
|
||||
:1007700030E0F901EA5DFF4F8491F901EA5CFF4F37
|
||||
:10078000D491F901EA5BFF4FC491CC23E9F08111C8
|
||||
:100790002CDFEC2FF0E0EE0FFF1FEA5AFF4FA59180
|
||||
:1007A000B491EC91ED2381E090E009F480E0DF91D9
|
||||
:1007B000CF910895275031099CE0981B892F233051
|
||||
:1007C0003105A8F28FEFD3CF80E090E0F0CF81B772
|
||||
:0E07D00081BFBDDE6FDC91DDFECFF894FFCF60
|
||||
:1007DE002828286F00FF8000800080FFFF0000FFA8
|
||||
:1007EE00FF0000FF00FF8000FFFFFF32000000014E
|
||||
:0207FE000100F8
|
||||
:00000001FF
|
||||
1644
pocketpsithemius.ino.lst
Normal file
1644
pocketpsithemius.ino.lst
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue