I wanted to know if my code chord to generate random chord progressions (and print it on a thermal printer) is good to go.
#include "Adafruit_Thermal.h"
#include <Wire.h>
#include "SoftwareSerial.h"
int randomNum1 = random(0, 4);
int randomNum2 = random(0, 82);
#define TX_PIN 6 // Arduino transmit YELLOW WIRE labeled RX on printer
#define RX_PIN 5 // Arduino receive GREEN WIRE labeled TX on printer
SoftwareSerial mySerial(RX_PIN , TX_PIN ); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor
byte customChar[8] = {
0b01110,
0b10001,
0b11111,
0b11001,
0b11001,
0b11111,
0b10001,
0b01110
};
String msgs1[]= {"1 beat of","2 beats of","3 beats of","1 measure of","2 measures of"};
String msgs2[]= {"Cmaj7","C#maj7","Dmaj7","D#maj7","Emaj7","Fmaj7","F#maj7","Gmaj7","G#maj7","Amaj7","A#maj7","Bmaj7","C-7","C#-7","D-7","D#-7","E-7","F-7","F#-7","G-7","G#-7","A-7","A#-7","B-7","C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "Cmaj7/9", "C#maj7/9","Dmaj7/9","D#maj7/9","Emaj7/9" "Fmaj7/9" "F#maj7/9", "Gmaj7/9", "G#maj7/9", "Amaj7/9","A#maj7/9","Bmaj7/9","C/D" ,"C#/D#","D/E","Eb/F","E/F#","F/G","F#/G#","G/A","G#/A#","A/B","A#/C","B/C#", "C-7/9", "C#-7/9", "D-7/9", "D#-7/9", "E-7/9", "F-7/9", "F#-7/9", "G-7/9", "G#-7/9", "A-7/9", "A#-7/9", "B-7/9", "C7", "C#7", "D7", "D#7", "E7", "F7", "F#7", "G7", "G#7", "A7", "A#7", "B7"};
//I need to replace these "msg1" and msgs 2 with more logical (and more through) matches!
// as of oct 17 this has been (i think) completed
void setup()
{
randomSeed(analogRead(A0));
Serial.begin(19200);
pinMode(7, OUTPUT); digitalWrite(7, LOW);
pinMode(4, INPUT); // set pin to input
digitalWrite(4, HIGH); // turn on pullup resistors
}
void loop()
{
if(digitalRead(4) == LOW)
{
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the first chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the second chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the third chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the fourth chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the fifth chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the sixth chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the seventh chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the eigth chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the ninth chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the tenth chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the eleventh chord and beat combonation
randomNum1 = random(0, 4);
printer.setSize('L');
printer.justify('C');
printer.println(msgs1[randomNum1]);
printer.feed(1);
randomNum2 = random(0, 35);
printer.setSize('L');
printer.justify('C');
printer.println(msgs2[randomNum2]);
printer.feed(1);
printer.justify('C');
printer.println("------------------------------");
printer.feed(2);
delay(2000);
//this is the twelth chord and beat combonation
//beneath it is the copyrights, etc.
//I used a custom char (as seen at the top) to make a copyright symbol
//howevever, I am not too sure if this will print on a thermal printer
//I will findout sooner or later, though.
printer.doubleHeightOn();
printer.setSize('L');
printer.justify('C');
printer.println("That's all!");
printer.feed(4);
delay(3000);
printer.doubleHeightOn();
printer.setSize('L');
printer.justify('C');
printer.write((uint8_t)0);
printer.feed(4);
printer.println("noah hellman");
delay(800);
}
else;
{
noah();
}
}
void noah()
{}