MacroBoard-ArduinoCode/Maybe/Maybe.ino

141 lines
2.5 KiB
Arduino
Raw Normal View History

2022-09-15 20:34:54 +00:00
/*
Macro Board
Made by Bozarre
*/
/*
* saving presets in eeprom
*/
#include <EEPROM.h>
2022-09-16 21:17:37 +00:00
int address = 0;
byte value;
struct MemSlot
{
char* displayName;
int adress;
byte value;
};
MemSlot memory[3] = //128 bytes for the Teensy LC
{ {"test1", 0, 0}};
2022-09-15 20:34:54 +00:00
/*
* 7 Segment 4 digits display
*/
#include "SevSeg.h"
2022-09-16 21:17:37 +00:00
2022-09-15 20:34:54 +00:00
SevSeg sevseg;
/*
* key button matrix
*/
#include <Key.h>
#include <Keypad.h>
const byte rows = 4; //four rows
const byte cols = 3; //three columns
char keys[rows][cols] = { // assiging arbitraty uid to each button
{1,5,9},
{2,6,10},
{3,7,11},
{4,8,12}
};
byte rowPins[rows] = {1, 2, 3, 0}; //connect to the row pinouts of the keypad
byte colPins[cols] = {21, 22, 23}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
/*
* Rotary Encoder
*/
#include <SimpleRotary.h>
SimpleRotary rotaryEncoder(19, 20, 4);
byte rotaryEncoderState = 0;
// Rotary push button
const int BUTTON_Rotary = 4;
bool BUTTON_Rotary_lastState = HIGH;
2022-09-16 21:17:37 +00:00
/*
* custom display animations
*/
#include "animations.h"
int animationFrame = 0;
bool animationLooping = true;
/*
* INIT
*/
void setup()
{
//debug
Serial.begin(9600);
Serial.println("setup start");
//Init display
byte numDigits = 4;
byte digitPins[] = {7, 8, 9, 6};
byte segmentPins[] = {10, 12, 14, 16, 17, 11, 13, 15};
bool resistorsOnSegments = true;
bool updateWithDelaysIn = true;
byte hardwareConfig = COMMON_CATHODE;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
sevseg.setBrightness(90);
//Init rotary encoders
rotaryEncoder.setDebounceDelay(2);
rotaryEncoder.setErrorDelay(100);
pinMode(BUTTON_Rotary, INPUT_PULLUP);
// Init keyboard output
Keyboard.begin();
Serial.println("setup complete");
}
/*
* Tick Loop
*/
void loop()
{
//INPUTS
char customKey = keypad.getKey();
rotaryEncoderState = rotaryEncoder.rotate();
//sevseg.refreshDisplay();
value = EEPROM.read(address);
Serial.print(address);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();
// advance to the next address of the EEPROM
address = address + 1;
// there are only 512 bytes of EEPROM, from 0 to 511, so if we're
// on address 512, wrap around to address 0
if (address == 128)
address = 0;
// Teensy 1.0 has 512 bytes
// Teensy 2.0 has 1024 bytes
// Teensy++ 1.0 has 2048 bytes
// Teensy++ 2.0 has 4096 bytes
delay(500);
}
void clickKey(int key)
{
Keyboard.press(key);
Keyboard.release(key);
}