Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

make storybox into a proper arduino sketch, and add button functional…

…ity to the code
  • Loading branch information...
commit 131d83a45764e0f2136fb3bc1777f8644fbddba6 1 parent 1304608
sweemeng authored April 09, 2011
87  gghc.pde
... ...
@@ -1,87 +0,0 @@
1  
-#include <LCD4Bit_mod.h> 
2  
-#include <EEPROM.h>
3  
-#include <Button.h>
4  
-//create object to control an LCD.  
5  
-//number of lines in display=1
6  
-LCD4Bit_mod lcd = LCD4Bit_mod(2); 
7  
-Button button = Button(2,PULLDOWN);
8  
-
9  
-long randno;
10  
-int EEPROM_SIZE = 1024;
11  
-
12  
-void setup() { 
13  
-  pinMode(13, OUTPUT);  //we'll use the debug LED to output a heartbeat
14  
-
15  
-  lcd.init();
16  
-  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
17  
-  //lcd.commandWrite(0x0F);//cursor on, display on, blink on.  (nasty!)
18  
-  lcd.clear();
19  
-  lcd.printIn("GGHC Phase 0");
20  
-  randomSeed(analogRead(0));
21  
-}
22  
-
23  
-void loop(){
24  
-  if(button.isPressed()){
25  
-	digitalWrite(13,HIGH);
26  
-        digitalWrite(10,HIGH);
27  
-        lcd.clear();
28  
-        lcd.printIn("Hello");
29  
-        randno = random(7);
30  
-        read_word(randno);
31  
-  }else{
32  
-	digitalWrite(13,LOW);
33  
-        digitalWrite(10,LOW);
34  
-  }
35  
-}
36  
-
37  
-void load_word(){
38  
-  char words[255] = "Hello:I:am:happy:sad:very:not";
39  
-  for(int i=0;i<29;i++){
40  
-    EEPROM.write(i,words[i]);
41  
-  }
42  
-}
43  
-
44  
-void print_clear(){
45  
- lcd.clear();  
46  
-}
47  
-
48  
-void print_word(char *c,int pos){
49  
-  //Just so we can abstract out lcd
50  
-  lcd.cursorTo(1,pos);
51  
-  lcd.printIn(c);
52  
-}
53  
-
54  
-void read_word(int pos){
55  
-  char check="";
56  
-  int count = 0;
57  
-  int new_pos = seek_delimiter(pos);
58  
-  print_clear();
59  
-  while(check != ":"){
60  
-    check = EEPROM.read(new_pos);
61  
-    if(check==":"){
62  
-      break;
63  
-    }
64  
-    print_word(check,count);
65  
-    count++;
66  
-    new_pos++;
67  
-  }
68  
-}
69  
-
70  
-int seek_delimiter(int pos){
71  
-  char check;
72  
-  int new_pos=-1;
73  
-  int i = 0;
74  
-  
75  
-  while(1){
76  
-    check = EEPROM.read(i);
77  
-    if(check == ':'){
78  
-      new_pos = i + 1;
79  
-      break;
80  
-    }
81  
-    if(i == EEPROM_SIZE){
82  
-      i = 0;
83  
-    }
84  
-    i++;
85  
-  }
86  
-  return new_pos;
87  
-}
112  storybox/storybox.pde
... ...
@@ -0,0 +1,112 @@
  1
+#include <LCD4Bit_mod.h> 
  2
+#include <EEPROM.h>
  3
+#include <Button.h>
  4
+
  5
+LCD4Bit_mod lcd = LCD4Bit_mod(2); 
  6
+Button button = Button(2,PULLDOWN);
  7
+
  8
+long randno;
  9
+int EEPROM_SIZE = 512;
  10
+int SIZE = 0;
  11
+
  12
+void setup() { 
  13
+  pinMode(13, OUTPUT);  //we'll use the debug LED to output a heartbeat
  14
+
  15
+  lcd.init();
  16
+  lcd.clear();
  17
+  randomSeed(analogRead(0));
  18
+  Serial.begin(9600);
  19
+  init_word();
  20
+}
  21
+
  22
+void loop(){
  23
+  lcd.clear();
  24
+  char words;
  25
+  if(button.isPressed()){
  26
+	digitalWrite(13,HIGH);
  27
+        digitalWrite(10,HIGH);
  28
+        randno = random(SIZE);
  29
+        words = get_char(randno);
  30
+        Serial.println(randno);
  31
+        print_clear();
  32
+        get_word(randno);
  33
+        delay(500);
  34
+  }else{
  35
+	digitalWrite(13,LOW);
  36
+        digitalWrite(10,LOW);
  37
+  }
  38
+}
  39
+
  40
+void load_word(int c){
  41
+  if(SIZE > EEPROM_SIZE){
  42
+    SIZE = EEPROM_SIZE;
  43
+  }
  44
+  EEPROM.write(SIZE,c);
  45
+  SIZE++;
  46
+  
  47
+}
  48
+
  49
+void print_clear(){
  50
+ lcd.clear();  
  51
+}
  52
+
  53
+void print_word(char *c,int pos){
  54
+  //Just so we can abstract out lcd
  55
+  lcd.cursorTo(1,pos);
  56
+  lcd.printIn(c);
  57
+}
  58
+
  59
+int seek_delimiter(int pos){
  60
+  int new_pos = 0;
  61
+  char *check;
  62
+  char c;
  63
+  int input;
  64
+  int i = pos;
  65
+  //Serial.println("Y");
  66
+  while(1){
  67
+    if(i > SIZE){
  68
+      i = 0;
  69
+    }
  70
+    c = get_char(i);
  71
+    *check = c;
  72
+    if(strcmp(check,":")==0){
  73
+      new_pos = i + 1;
  74
+      break;
  75
+    }
  76
+    
  77
+    i++;
  78
+  }
  79
+  return new_pos;
  80
+}
  81
+
  82
+char get_char(int pos){
  83
+  int letter = EEPROM.read(pos);
  84
+  return (char)letter;
  85
+}
  86
+
  87
+void get_word(int pos){
  88
+  pos = seek_delimiter(pos);
  89
+  
  90
+  int i = 0;
  91
+  char *check;
  92
+  char c;
  93
+  while(1){
  94
+    c = get_char(pos);
  95
+    *check = c;
  96
+    if(strcmp(check,":")==0){
  97
+      
  98
+      break;
  99
+    }
  100
+    //Serial.println(check);
  101
+    print_word(&c,i);
  102
+    i++;
  103
+    pos++;
  104
+  }
  105
+}
  106
+
  107
+void init_word(){
  108
+  char words[100] = "I:am:happy:sad:you:are:very:not";
  109
+  for(int i=0;i<100;i++){
  110
+    load_word((int)words[i]);
  111
+  }
  112
+}

0 notes on commit 131d83a

Please sign in to comment.
Something went wrong with that request. Please try again.