#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "button.h" // from https://github.com/e-tinkers/button
// midi output from https://docs.arduino.cc/built-in-examples/communication/Midi
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);
#define CV_OUT_PIN 9
#define UP_BUTTON_PIN 2
#define DOWN_BUTTON_PIN 3
#define RUN_SELECT_BUTTON_PIN 4
#define STOP_BACK_BUTTON_PIN 5
#define MIN_INT 0
#define MAX_INT 255
#define RUN_STOP_TEXT "Run Stop"
#define SELECT_BACK_TEXT "Select Back"
#define SEQUENCER_MODE 0
#define RANDOM_MODE 1
#define MIDI_MODE 2
#define SETTINGS_MODE 3
const String modes[] = { "CV Sequencer", "CV Random", "Midi Test", "Settings" };
int mode_number = 0;
String topLine = modes[mode_number]+" Mode";
String bottomLine = RUN_STOP_TEXT;
// These will be the changeable settings
long output_length = 1000; // in ms
const String settings_text[] = { "output time (secs)", "Sequence Length",
"Sequence Pattern", "CV out while setting",
"Note 1","Note 2","Note 3","Note 4","Note 5","Note 6","Note 7","Note 8"};
const String pattern_text[] = {"Forward", "Forward/Backward", "Forward/Backward Short", "Backward", "Backward/Forward", "Random"};
const int FORWARD = 0;
const int FORWARD_BACKWARD = 1;
const int FORWARD_BACKWARD_SHORT = 2;
const int BACKWARD = 3;
const int BACKWARD_FORWARD = 4;
const int RANDOM_ORDER = 5;
const int setting_total = 12 - 1;
const int pattern_total = 6 -1;
int notes[] = { 85,89,93,98,98,93,89,85};
const int notes_total = 8 - 1;
float output_time = 0.5;
int number_steps = 8;
int pattern = 0;
bool cv_while_setting = false;
const float output_time_step = 0.1;
const float min_output_time = 0.1;
const float max_output_time = 5.0;
const int min_steps = 1;
const int max_steps = 8;
// midi
// not
const String midi_notes[] = {"A0","A#0/Bb0","B0",
"C1","C#1/Db1","D1","D#1/Eb1","E1","F1","F#1/Gb1","G1","G#1/Ab1","A1","A#1/Bb1","B1",
"C2","C#2/Db2","D2","D#2/Eb2","E2","F2","F#2/Gb2","G2","G#2/Ab2","A2","A#2/Bb2","B2",
"C3","C#3/Db3","D3","D#3/Eb3","E3","F3","F#3/Gb3","G3","G#3/Ab3","A3","A#3/Bb3","B3",
"C4 (middle C)","C#4/Db4","D4","D#4/Eb4","E4","F4","F#4/Gb4","G4","G#4/Ab4","A4","A#4/Bb4","B4",
"C5","C#5/Db5","D5","D#5/Eb5","E5","F5","F#5/Gb5","G5","G#5/Ab5","A5","A#5/Bb5","B5",
"C6","C#6/Db6","D6","D#6/Eb6","E6","F6","F#6/Gb6","G6","G#6/Ab6","A6","A#6/Bb6","B6",
"C7","C#7/Db7","D7","D#7/Eb7","E7","F7","F#7/Gb7","G7","G#7/Ab7","A7","A#7/Bb7","B7",
"C8","C#8/Db8","D8","D#8/Eb8","E8","F8","F#8/Gb8","G8","G#8/Ab8","A8","A#8/Bb8","B8",
"C9","C#9/Db9","D9","D#9/Eb9","E9","F9","F#9/Gb9","G9" };
int midi_seq_length = 62;
const int mini_max_seq_length = 255;
int midi_channel = 1; // (1 - 16) channel 1 is 0 in the message
// this should be node to joy
//String midi_notes_to_play[] = { "62","62","63","64","64","63","62","61","60","60","61","62","62","61","61","62","62","63","64","64","63","62","61","60","60","61","62","61","60","60","61","61","62","60","61","62","63","62","60","61","62","63","62","61","60","62","58","62","62","63","64","64","63","62","61","60","60","61","62","61","60","60"};
Button up_button;
Button down_button;
Button run_select_button;
Button stop_back_button;
void setup() {
// put your setup code here, to run once:
pinMode(CV_OUT_PIN, OUTPUT);
up_button.begin(UP_BUTTON_PIN);
down_button.begin(DOWN_BUTTON_PIN);
run_select_button.begin(RUN_SELECT_BUTTON_PIN);
stop_back_button.begin(STOP_BACK_BUTTON_PIN);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(5000);
// Set MIDI baud rate:
//Serial.begin(31250);
// Display start screen
// change_mode(0);
// Display start screen
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0,0);
display.println("hello");
display.println("2");
display.println("3");
display.println("4");
display.display();
delay(5000);
}
void loop() {
}