From 449d3c098e1a8771bf282e5695c14e46971948a8 Mon Sep 17 00:00:00 2001 From: unlockable Date: Sat, 9 Sep 2023 21:54:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95words=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 8By8/8By8.ino | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/8By8/8By8.ino b/8By8/8By8.ino index 19f6a3c..8f949ce 100644 --- a/8By8/8By8.ino +++ b/8By8/8By8.ino @@ -874,6 +874,11 @@ byte cube_step = 1; bool rain_create_new = false; +String display_string = ""; +int letter_create_layer_count = 0; +// When count to 7, it's time to draw the new letter. +int next_char_ptr = 0; + void setup() { for (int i = 22; i < 46; i++) { pinMode(i, OUTPUT); @@ -1093,7 +1098,53 @@ void clock() { } void words() { - return; + if (Serial.available()) { + byte input_char = Serial.read(); + if (input_char >= 'A' && input_char <= 'Z') { + display_string.concat(input_char); + } + + if (input_char >= 'a' && input_char <= 'z') { + display_string.concat(input_char - 'a' + 'A'); + } + + if (input_char == '?') { + Serial.print("Current string: "); + Serial.println(display_string); + } + + if (input_char == '/') { + Serial.println("Cleared input."); + } + } + + delay(50); + + // Move everything one light forward. + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + Cube::LED_brightness[i][j] = Cube::LED_brightness[i][j] >> 2; + Cube::LED_status[i][j] = Cube::LED_status[i][j] >> 2; + } + } + + letter_create_layer_count++; + + if (letter_create_layer_count < 7 ) { + // The previous have not been moved out + return; + } + + letter_create_layer_count = 0; + + if (next_char_ptr == display_string.length()) { + // Displayed all chars. 'Display' a space and reverse to the first char. + next_char_ptr = 0; + return; + } + + Cube::draw_letter(1, 7, 7, display_string[next_char_ptr] - 'A', 2, 3); + next_char_ptr++; } void calculate_and_draw() {