Definitely not elegant or optimal, but here's what is presently running this thing:
#include <SevenSeg.h>
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
SevenSeg disp(10,12,7,8,9,11,A2);
const int numOfDigits=4;
int digitPins[numOfDigits]={5,4,2,6};
volatile int indexMode = 0;
char* nounAZ[] = {"lamp", "desk", " car", " dog", " cat", "door", "bike", "shoe", "tree", "shed", "fork", " tea", "hill", " job", "head", "food", " cup", "cafe", " dad", " mom"};
char* verbAZ[] = {" is", " was", " are", " ate", "goes", "runs", "eats", "wins", "sees", "gets", "puts", "cuts", " had"};
char* adjAZ[] = {" big", "blue", "tiny", " red", " bad", "good", "easy", " wee", "huge", " mad", " sad", "glad", " rad", "near", " far", " low", "high", "wide", "thin", " hot", "cold", "cool", "warm"};
int poem1[] = {8, 1, 2, 3, 1, 1, 2, 3, 1};
int poemLength = poem1[0] +1;
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345);
void setup() {
disp.setDigitPins(numOfDigits,digitPins);
disp.setDPPin(13);
pinMode(3, INPUT);
attachInterrupt(1, changeMode, FALLING);
if(!mag.begin())
}
// the loop function runs over and over again forever
void loop() {
switch (indexMode) {
case 0:
for (int pmode=1; pmode<150; pmode++) {
disp.write("poem");
delay(10);
}
displayPoem();
break;
case 1:
for (int tmode=1; tmode<150; tmode++) {
disp.write("time");
delay(10);
}
printTime();
break;
case 2:
for (int dmode=1; dmode<150; dmode++) {
disp.write("dirn");
delay(10);
}
printDirn();
break;
}
}
void displayPoem(){
int i = 1;
int poemLength = poem1[0] + 1;
while (i < poemLength) {
int poemIndex = poem1[i];
if (poemIndex == 1)
{
printNoun();
}
else if (poemIndex == 2)
{
printVerb();
}
else if (poemIndex == 3)
{
printAdj();
}
else
{
Serial.println("oops");
}
i++;
}
for (int j=0; j<=129; j++) {
disp.write("fini");
delay(5);
}
}
void printNoun(){
randomSeed(analogRead(1));
int numTD;
numTD = random(19);
delay(150);
for (int b=0; b <=100; b++){
disp.write(nounAZ[numTD]);
delay(5);
}
delay(500);
}
void printVerb(){
randomSeed(analogRead(1));
int numTD;
numTD = random(12);
delay(150);
for (int b=0; b <=100; b++){
disp.write(verbAZ[numTD]);
delay(5);
}
delay(500);
}
void printAdj(){
randomSeed(analogRead(1));
int numTD;
numTD = random(22);
delay(150);
for (int b=0; b <=100; b++){
disp.write(adjAZ[numTD]);
delay(5);
}
delay(500);
}
void printTime(){
tmElements_t tm;
if (RTC.read(tm)) {
}
//delay(1000);
int hours = tm.Hour;
int minutes = tm.Minute;
for (int j=0; j<=333; j++) {
disp.writeClock(hours,minutes);
}
delay(5);
}
void printDirn(){
//disp.write("dirn");
/* Get a new sensor event */
sensors_event_t event;
mag.getEvent(&event);
float Pi = 3.14159;
// Calculate the angle of the vector y,x
float heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / Pi;
// Normalize to 0-360
if (heading < 0)
{
heading = 360 + heading;
}
for (int c=0; c <333; c++) {
disp.write(heading);
}
delay(15);
}
void changeMode() {
++indexMode %= 3;
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.