/* * SerialTextInkShield.pde - Serial communication InkShield text sketch * Copyright 2011, Nicholas C Lewis, GNU Lesser General Public License * http://nicholasclewis.com/inkshield/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * http://www.gnu.org/licenses/lgpl-2.1.html * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* 2011-12-2 / v.01 dosman / http://www.bloominglabs.org/index.php/InkShield_Project * 5 Button code borrowed from: * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226896251 */ // ################################################ 5 button input #define ERROR_WINDOW 20 // +/- this value #define BUTTONDELAY 50 #define DEBUG_ON int analogPin = 5; // switch circuit input connected to analog pin 3 long buttonLastChecked = 0; // variable to limit the button getting checked every cycle // All strings currently must be ALL UPPER-CASE, code should be modified to auto-uppercase some day... String msg1 = "WWW.BLOOMINGLABS.ORG"; String msg2 = "DOSMAN WAS HERE"; String msg3 = "OMNISCAN!"; String msg4 = "FOOLS"; String msg5 = "WDFS"; int msg1length = msg1.length(); int msg2length = msg2.length(); int msg3length = msg3.length(); int msg4length = msg4.length(); int msg5length = msg5.length(); // ################################################## #include //incoming serial byte int inByte = 0; //initialize data (font) table const int minChar = 32; const int maxChar = 96; //each letter is 10 rows const int rowsPerChar = 10; const int fontSize = (maxChar-minChar+1)*rowsPerChar; const word font[fontSize] = { // ASCII 032-048; $20-$2F // 'Space' thru "/" 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '!' 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000111111110011, 0b0000111111110011, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '"' 0b0000000000000000, 0b0000000000000000, 0b0000111000000000, 0b0000111000000000, 0b0000000000000000, 0b0000000000000000, 0b0000111000000000, 0b0000111000000000, 0b0000000000000000, 0b0000000000000000, // '#' 0b0000000110011000, 0b0000000110011110, 0b0000000111111110, 0b0000011111111000, 0b0000011110011000, 0b0000000110011110, 0b0000000111111110, 0b0000011111111000, 0b0000011110011000, 0b0000000110011000, // '$' 0b0000001100001100, 0b0000011110001110, 0b0000010011000010, 0b0000010011000010, 0b0000111111111111, 0b0000111111111111, 0b0000010000110010, 0b0000010000110010, 0b0000011100011110, 0b0000001100001100, // '%' 0b0000001100000110, 0b000001001001110, 0b0000010010011100, 0b0000001100111000, 0b0000000001110000, 0b0000000011100000, 0b0000000111001100, 0b0000001110010010, 0b0000011100010010, 0b0000011000001100, // '&' 0b0000001110011100, 0b0000011111111110, 0b0000110001100011, 0b0000110011110011, 0b0000011110110011, 0b0000001100011110, 0b0000000000111100, 0b0000000011110110, 0b0000000011000111, 0b0000000010000011, // ''' 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000111000000000, 0b0000111000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '(' 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000001111111100, 0b0000111111111111, 0b0000110000000011, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // ')' 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000110000000011, 0b0000111111111111, 0b0000001111111100, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '*' 0b0000000000000000, 0b0000000011001000, 0b0000000011011100, 0b0000000001111000, 0b0000001111110000, 0b0000001111110000, 0b0000000001111000, 0b0000000011011100, 0b0000000011001000, 0b0000000000000000, // '+' 0b0000000000000000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000001111111100, 0b0000001111111100, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000000000000, // ',' 0b0000000000000000, 0b0000000000001101, 0b0000000000001110, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '-' 0b0000000000000000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000000000000, // '.' 0b0000000000000000, 0b0000000000001100, 0b0000000000001100, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '/' 0b0000000000000110, 0b0000000000001110, 0b0000000000011100, 0b0000000000111000, 0b0000000001110000, 0b0000000011100000, 0b0000000111000000, 0b0000001110000000, 0b0000011100000000, 0b0000011000000000, // ASCII 048-057; $30-$39 // "0" thru "9" // '0' 0b0000001111111100, 0b0000011111111110, 0b0000011000000110, 0b0000110000001011, 0b0000100001110001, 0b0000100011100001, 0b0000110100000011, 0b0000011000000110, 0b0000011111111110, 0b0000001111111100, // '1' 0b0000000000000000, 0b0000000000000000, 0b0000110000000011, 0b0000110000000011, 0b0000111111111111, 0b0000111111111111, 0b0000000000000011, 0b0000000000000011, 0b0000000000000000, 0b0000000000000000, // '2' 0b0000001100001111, 0b0000011000011111, 0b0000011000011011, 0b0000110000110011, 0b0000110000110011, 0b0000110001100011, 0b0000110001100011, 0b0000011011000011, 0b0000011111000011, 0b0000001110000011, // '3' 0b0000001000000100, 0b0000011000000110, 0b0000110000000011, 0b0000110001100011, 0b0000100001100001, 0b0000100001100001, 0b0000110011110011, 0b0000110011110011, 0b0000011110011110, 0b0000001100001100, // '4' 0b0000000001110000, 0b0000000011110000, 0b0000000110110000, 0b0000001100110000, 0b0000011000110000, 0b0000110000110000, 0b0000111111111111, 0b0000111111111111, 0b0000000000110000, 0b0000000000110000, // '5' 0b0000111110000100, 0b0000111111000110, 0b0000110011000011, 0b0000110011000011, 0b0000110011000001, 0b0000110011000001, 0b0000110011000011, 0b0000110011000011, 0b0000110001111110, 0b0000110000111100, // '6' 0b0000000011111100, 0b0000000111111110, 0b0000001101100011, 0b0000011001100011, 0b0000110001100001, 0b0000110001100001, 0b0000110001100011, 0b0000110001100011, 0b0000110000111110, 0b0000000000011100, // '7' 0b0000110000000011, 0b0000110000000111, 0b0000110000001100, 0b0000110000011000, 0b0000110000110000, 0b0000110001100000, 0b0000110011000000, 0b0000110110000000, 0b0000111100000000, 0b0000111000000000, // '8' 0b0000001100001100, 0b0000011110011110, 0b0000010011110010, 0b0000110001100011, 0b0000100001100001, 0b0000100001100001, 0b0000110001100011, 0b0000010011110010, 0b0000011110011110, 0b0000001100001100, // '9' 0b0000001110000000, 0b0000011111000011, 0b0000110001100011, 0b0000110001100011, 0b0000100001100011, 0b0000100001100011, 0b0000110001100110, 0b0000110001101100, 0b0000011111111000, 0b0000001111110000, // ASCII 058-064; $3A-$40 // ":" thru "@" // ':' 0b0000000000000000, 0b0000000110001100, 0b0000000110001100, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // ';' 0b0000000000000000, 0b0000000110001101, 0b0000000110001110, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '<' 0b0000000000000000, 0b0000000000000000, 0b0000000001000000, 0b0000000011100000, 0b0000000110110000, 0b0000001100011000, 0b0000011000001100, 0b0000010000000100, 0b0000000000000000, 0b0000000000000000, // '=' 0b0000000000000000, 0b0000000000000000, 0b0000000110011000, 0b0000000110011000, 0b0000000110011000, 0b0000000110011000, 0b0000000110011000, 0b0000000110011000, 0b0000000000000000, 0b0000000000000000, // '>' 0b0000000000000000, 0b0000000000000000, 0b0000010000000100, 0b0000011000001100, 0b0000001100011000, 0b0000000110110000, 0b0000000011100000, 0b0000000001000000, 0b0000000000000000, 0b0000000000000000, // '?' 0b0000001100000000, 0b0000011100000000, 0b0000110000000000, 0b0000110000000000, 0b0000100000011011, 0b0000100000111011, 0b0000110001100000, 0b0000110011000000, 0b0000011110000000, 0b0000001100000000, // '@' 0b0000001111111100, 0b0000011111111110, 0b0000011000000110, 0b0000110001110011, 0b0000100010001001, 0b0000100010001001, 0b0000110011110011, 0b0000011000001010, 0b0000011111111000, 0b0000001111110000, // ASCII 065-090; $41-$5A // "A" thru "Z" 0b0000000011111111, 0b0000000111111111, 0b0000001101100000, 0b0000011001100000, 0b0000110001100000, 0b0000110001100000, 0b0000011001100000, 0b0000001101100000, 0b0000000111111111, 0b0000000011111111, // 'B' 0b0000111111111111, 0b0000111111111111, 0b0000110001100011, 0b0000110001100011, 0b0000110001100011, 0b0000110001100011, 0b0000110001100011, 0b0000110001100011, 0b0000011111111111, 0b0000001110011110, // 'C' 0b0000001111111100, 0b0000011111111110, 0b0000011000000110, 0b0000110000000011, 0b0000100000000001, 0b0000100000000001, 0b0000110000000011, 0b0000011000000110, 0b0000011100001110, 0b0000001100001100, // 'D' 0b0000111111111111, 0b0000111111111111, 0b0000110000000011, 0b0000110000000011, 0b0000110000000011, 0b0000110000000011, 0b0000010000000010, 0b0000011000000110, 0b0000011111111110, 0b0000001111111100, // 'E' 0b0000111111111111, 0b0000111111111111, 0b0000110001100011, 0b0000110001100011, 0b0000110001100011, 0b0000110001100011, 0b0000110001100011, 0b0000110000000011, 0b0000110000000011, 0b0000110000000011, // 'F' 0b0000111111111111, 0b0000111111111111, 0b0000110001100000, 0b0000110001100000, 0b0000110001100000, 0b0000110001100000, 0b0000110001100000, 0b0000110000000000, 0b0000110000000000, 0b0000110000000000, // 'G' 0b0000001111111100, 0b0000011111111110, 0b0000011000000110, 0b0000110000000011, 0b0000100000000001, 0b0000100000000001, 0b0000110001100011, 0b0000011001100011, 0b0000011001111110, 0b0000001001111100, // 'H' 0b0000111111111111, 0b0000111111111111, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000000001100000, 0b0000111111111111, 0b0000111111111111, // 'I' 0b0000000000000000, 0b0000110000000011, 0b0000110000000011, 0b0000110000000011, 0b0000111111111111, 0b0000111111111111, 0b0000110000000011, 0b0000110000000011, 0b0000110000000011, 0b0000000000000000, // 'J' 0b0000000000111100, 0b0000000000011110, 0b0000000000000110, 0b0000000000000011, 0b0000000000000001, 0b0000000000000001, 0b0000110000000011, 0b0000110000000110, 0b0000111111111110, 0b0000111111111100, // 'K' 0b0000111111111111, 0b0000111111111111, 0b0000000011000000, 0b0000000110100000, 0b0000000100110000, 0b0000001100011000, 0b0000011000001100, 0b0000010000000110, 0b0000110000000011, 0b0000100000000001, // 'L' 0b0000111111111111, 0b0000111111111111, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, // 'M' 0b0000111111111111, 0b0000011111111111, 0b0000001000000000, 0b0000000110000000, 0b0000000011100000, 0b0000000011100000, 0b0000000110000000, 0b0000001000000000, 0b0000011111111111, 0b0000111111111111, // 'N' 0b0000111111111111, 0b0000111111111111, 0b0000001100000000, 0b0000000110000000, 0b0000000011100000, 0b0000000001110000, 0b0000000000011000, 0b0000000000001100, 0b0000111111111111, 0b0000111111111111, // 'O' 0b0000001111111100, 0b0000011111111110, 0b0000011000000110, 0b0000110000000011, 0b0000100000000001, 0b0000100000000001, 0b0000110000000011, 0b0000011000000110, 0b0000011111111110, 0b0000001111111100, // 'P' 0b0000111111111111, 0b0000111111111111, 0b0000110001100000, 0b0000110001100000, 0b0000110001100000, 0b0000110001100000, 0b0000110001100000, 0b0000111011000000, 0b0000011111000000, 0b0000001110000000, // 'Q' 0b0000001111111100, 0b0000011111111110, 0b0000011000000110, 0b0000110000000011, 0b0000100000001001, 0b0000100000001101, 0b0000110000000110, 0b0000011000000011, 0b0000011111111101, 0b0000001111111001, // 'R' 0b0000111111111111, 0b0000111111111111, 0b0000110001100000, 0b0000110001100000, 0b0000110001110000, 0b0000110001111000, 0b0000110001111100, 0b0000111011001110, 0b0000011111000111, 0b0000001110000011, // 'S' 0b0000001100001100, 0b0000011110001110, 0b0000010011000010, 0b0000110011000011, 0b0000100001100001, 0b0000100001100001, 0b0000110000110011, 0b0000010000110010, 0b0000011100011110, 0b0000001100001100, // 'T' 0b0000110000000000, 0b0000110000000000, 0b0000110000000000, 0b0000110000000000, 0b0000111111111111, 0b0000111111111111, 0b0000110000000000, 0b0000110000000000, 0b0000110000000000, 0b0000110000000000, // 'U' 0b0000111111111100, 0b0000111111111110, 0b0000000000000110, 0b0000000000000011, 0b0000000000000001, 0b0000000000000001, 0b0000000000000011, 0b0000000000000010, 0b0000111111111110, 0b0000111111111100, // 'V' 0b0000110000000000, 0b0000011111000000, 0b0000000011111000, 0b0000000000011110, 0b0000000000000011, 0b0000000000000011, 0b0000000000011110, 0b0000000011111000, 0b0000011111000000, 0b0000110000000000, // 'W' 0b0000111111111111, 0b0000111111111110, 0b0000000000000100, 0b0000000000011000, 0b0000000001110000, 0b0000000001110000, 0b0000000000011000, 0b0000000000000100, 0b0000111111111110, 0b0000111111111111, // 'X' 0b0000110000000011, 0b0000011000000110, 0b0000001100001100, 0b0000000110011000, 0b0000000011110000, 0b0000000011110000, 0b0000000110011000, 0b0000001100001100, 0b0000011000000110, 0b0000110000000011, // 'Y' 0b0000110000000000, 0b0000011000000000, 0b0000001100000000, 0b0000000110000000, 0b0000000011111111, 0b0000000011111111, 0b0000000110000000, 0b0000001100000000, 0b0000011000000000, 0b0000110000000000, // 'Z' 0b0000110000000111, 0b0000110000001111, 0b0000110000011011, 0b0000110000110011, 0b0000110001100011, 0b0000110001100011, 0b0000110011000011, 0b0000110110000011, 0b0000111100000011, 0b0000111000000011, // ASCII 091-096; $5B-$60 // "[" thru "`" // '[' 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000111111111111, 0b0000111111111111, 0b0000110000000011, 0b0000110000000011, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '\' 0b0000110000000000, 0b0000111000000000, 0b0000011100000000, 0b0000001110000000, 0b0000000111000000, 0b0000000011100000, 0b0000000001110000, 0b0000000000111000, 0b0000000000011100, 0b0000000000001100, // ']' 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000110000000011, 0b0000110000000011, 0b0000111111111111, 0b0000111111111111, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, // '^' 0b0000000000000000, 0b0000000110000000, 0b0000001100000000, 0b0000011000000000, 0b0000110000000000, 0b0000110000000000, 0b0000011000000000, 0b0000001100000000, 0b0000000110000000, 0b0000000000000000, // '_' 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, 0b0000000000000011, // '`' 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000110000000000, 0b0000111000000000, 0b0000001100000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, }; InkShieldA0A3 MyInkShield(2); void setup() { Serial.begin(9600); //char* messages[]={"This is string 1", "This is string 2", "This is string 3", "This is string 4", "This is string 5","This is string 6"}; } void loop() { /* // if we get a valid byte, read analog ins: if (Serial.available() > 0) { // get incoming byte: inByte = Serial.read(); if(inByte>96){ //if lowercase letter inByte-=32; //make uppercase } spray_letter(inByte); } */ /* // http://arduino.cc/en/Reference/StringToCharArray string.toCharArray(buf, len) Parameters string: a variable of type String buf: the buffer to copy the characters into (char []) len: the size of the buffer (unsigned int) */ if( buttonLastChecked == 0 ) // see if this is the first time checking the buttons buttonLastChecked = millis()+BUTTONDELAY; // force a check this cycle if( millis() - buttonLastChecked > BUTTONDELAY ) { // make sure a reasonable delay passed if( int buttNum = buttonPushed(analogPin) ) { Serial.print("Button "); Serial.print(buttNum); Serial.println(" was pushed."); switch (buttNum) { case 1: Serial.println(msg1length); for (int i = 0; i < msg1length; i++){ Serial.print(msg1[i]); Serial.print(" "); //if(msg1[i]>96){ //if lowercase letter //msg1[i]-=32; //make uppercase spray_letter(msg1[i]); } break; case 2: Serial.println(msg2length); for (int i = 0; i < msg2length; i++){ Serial.print(msg2[i]); Serial.print(" "); spray_letter(msg2[i]); } break; case 3: Serial.println(msg3length); for (int i = 0; i < msg3length; i++){ spray_letter(msg3[i]); } break; case 4: Serial.println(msg4length); for (int i = 0; i < msg4length; i++){ spray_letter(msg4[i]); } break; case 5: Serial.println(msg5length); for (int i = 0; i < msg5length; i++){ spray_letter(msg5[i]); } break; } } buttonLastChecked = millis(); // reset the lastChecked value } } void spray_letter(int letter) { if(letter>=minChar && letter<=maxChar) { for(int row=0; row= 923 and val <= 1023 ) // Serial.println("switch 0 pressed/triggered"); //if( val >= 780 and val <= 880 ) { // 830 if( val > 1022 ) { #ifdef DEBUG_ON Serial.println("switch 1 pressed/triggered"); #endif return 1; } else if ( val >= (773-ERROR_WINDOW) and val <= (773+ERROR_WINDOW) ) { // 630 #ifdef DEBUG_ON Serial.println("switch 2 pressed/triggered"); #endif return 2; } else if ( val >= (526-ERROR_WINDOW) and val <= (526+ERROR_WINDOW) ) { // 430 #ifdef DEBUG_ON Serial.println("switch 3 pressed/triggered"); #endif return 3; } else if ( val >= (274-ERROR_WINDOW) and val <= (274+ERROR_WINDOW) ) { // 230 #ifdef DEBUG_ON Serial.println("switch 4 pressed/triggered"); #endif return 4; } else if( val >= 0 and val <= (20+ERROR_WINDOW) ) { #ifdef DEBUG_ON Serial.println("switch 5 pressed/triggered"); #endif return 5; } else return 0; // no button found to have been pushed } // ########################## end button read