Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 97 lines (78 sloc) 1.956 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#include <LiquidCrystal.h>
#include <Wire.h>

#include <WordStorage.h>
#include <TrueRandom.h>
#include <Bounce.h>
#include <WordGenerator.h>

#define button1 2
#define lcdBacklit 3
#define buzzer 10
#define statusLed 13

LiquidCrystal lcd(12,11,7,6,5,4);
Bounce bouncer = Bounce(button1,50);

WordGenerator generator(7);
int storage_size = 0;
char *s_word;
void setup() {
  pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat

  lcd.begin(16,2);
  randomSeed(analogRead(0));
  Serial.begin(9600);
  lcd.print("HSKL StoryBox");
  pinMode(statusLed,OUTPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(button1,INPUT);
  pinMode(lcdBacklit,OUTPUT);
  digitalWrite(lcdBacklit,HIGH);
}

void loop(){

  bouncer.update();
  int value = bouncer.read();

  data_load();
  
  //analogWrite(lcdBacklit,15);
  if(value == HIGH){
    Serial.print('ping');
    lcd.clear();
    int segment = TrueRandom.random(0,7);
    digitalWrite(statusLed,HIGH);
    digitalWrite(buzzer,HIGH);

    generator.get_segment(segment);

    free(s_word);
    *s_word = NULL;
    s_word = generator.word_select();

    int s_start = generator.get_word_begin();
    int s_end = generator.get_word_end();
        
    int l_cursor = 0;
        
    for(int i = s_start+1;i<s_end;i++){
      lcd.setCursor(l_cursor,0);
      char letter = generator.get_storage(i);
      lcd.print(letter);
      Serial.write(letter);
      l_cursor++;
    }
    
    Serial.println(" ");
    
  }else{
    digitalWrite(statusLed,LOW);
    digitalWrite(buzzer,LOW);
  }
}

void data_load(){
  storage_size = 0;
  int value;
  value = Serial.read();

  if(value == 60){
    while(value != 62){
      value = Serial.read();
      Serial.write(value);
      if(value == 62){
        break;
      }
      generator.put_storage(storage_size,value);
      storage_size++;
    }
  }
  generator.put_storage(0,0);
  for(int i=0;i<storage_size;i++){
    Serial.print(generator.get_storage(i));
  }
}
Something went wrong with that request. Please try again.