Permalink
Browse files

added a find the right position for reading from memory

  • Loading branch information...
1 parent c3ec904 commit 0f879fb9d61c222c251aaee9391839e6a782a6b1 @sweemeng committed Apr 24, 2011
Showing with 33 additions and 9 deletions.
  1. +7 −2 libraries/storyboard/WordGenerator.cpp
  2. +26 −7 storybox/storybox.pde
@@ -16,7 +16,7 @@ int WordGenerator::byte_to_int(byte *header){
}
void WordGenerator::get_segment(int pos){
- int begin = 0 + (4 * pos);
+ int begin = 1 + (4 * pos);
int mid = begin + 4;
int end = mid + 4;
byte s_start[4];
@@ -70,14 +70,15 @@ char *WordGenerator::word_select(){
if(word_start == this->segment_end){
word_start = this->segment_begin;
}
-
+ Serial.println(word_start);
this->begin = word_start;
int word_end = this->get_delimiter(word_start+1);
//Serial.println(this->storage.read(word_start));
//Serial.println(this->storage.read(word_end));
word_start = word_start + 1;
word_end = word_end;
this->end = word_end;
+ Serial.println(word_end);
int word_size = word_end - word_start;
//Serial.println(word_size);
char *s_word;
@@ -86,13 +87,17 @@ char *WordGenerator::word_select(){
for(int i = word_start;i < word_end;i++){
s_word[count] = storage.read(i);
+ Serial.write(s_word[count]);
//s_word++;
count++;
if(count == word_size){
+
+
break;
}
//delay(500);
}
+ Serial.println(sizeof(*s_word));
return s_word;
}
View
@@ -16,6 +16,7 @@ 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
@@ -31,19 +32,21 @@ void setup() {
}
void loop(){
- char *s_word;
+
bouncer.update();
int value = bouncer.read();
lcd.clear();
data_load();
- analogWrite(lcdBacklit,10);
if(value == HIGH){
int segment = TrueRandom.random(0,7);
digitalWrite(statusLed,HIGH);
digitalWrite(buzzer,HIGH);
- generator.get_segment(segment);
+ generator.get_segment(0);
+ free(s_word);
+ *s_word = NULL;
s_word = generator.word_select();
lcd.printIn(s_word);
+
Serial.println(s_word);
delay(500);
@@ -55,10 +58,26 @@ void loop(){
void data_load(){
storage_size = 0;
- while(Serial.available() > 0){
- int value = Serial.read();
- digitalWrite(13,HIGH);
+ int value;
+ value = Serial.read();
+ //Serial.write(value);
+ 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);
+ if(storage_size > 0){
+ Serial.println(" ");
+ for(int i=0;i<storage_size;i++){
+ Serial.print((char)generator.get_storage(i));
+ }
+ }
+
}

0 comments on commit 0f879fb

Please sign in to comment.