147
edits
|  (change Code) | |||
| Line 132: | Line 132: | ||
| int lcdRows = 2; | int lcdRows = 2; | ||
| // set LCD address, number of columns and rows | // set LCD address, number of columns and rows | ||
| // if  | // if don't know the display address, run an I2C scanner sketch | ||
| LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);   | LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);   | ||
| // set up display texts   | // set up display texts   | ||
| Line 139: | Line 139: | ||
| // A string variable used to store accumulated ASCII conversations | // A string variable used to store accumulated ASCII conversations | ||
| String dialogue = "";   | String dialogue = "";   | ||
| // for counting  | // for counting characters from ASCII codes  | ||
| int charCount = 0;       | int charCount = 0;       | ||
| /* Function: Scrolling Texts */ | /* Function: Scrolling Texts */ | ||
| // The function  | // The function accepts the following arguments: | ||
| // row: row number where the text will be displayed | // row: row number where the text will be displayed | ||
| // message: message to scroll | // message: message to scroll | ||
| Line 296: | Line 296: | ||
|    ThingSpeak.writeField(ChannelNumber2, 1, mq2g3V, WriteAPIkey2); |    ThingSpeak.writeField(ChannelNumber2, 1, mq2g3V, WriteAPIkey2); | ||
|    // LCD  |    // LCD messages    | ||
|    // convert MQ-2's value to ASCII code |    // convert MQ-2's value to ASCII code | ||
|    int ascii_value = map(mq2g3V, 1000, 2500, 34, 126); |    int ascii_value = map(mq2g3V, 1000, 2500, 34, 126); | ||
| Line 303: | Line 303: | ||
|    // a new character is added to the string (the previous one is kept) |    // a new character is added to the string (the previous one is kept) | ||
|    dialogue += ascii_char ; |    dialogue += ascii_char ; | ||
|    charCount++; //  |    charCount++; // accumulated character count +1 | ||
|    // Try using spaces to create a variation in sentence length for a more natural dialogue effect. |    // Try using spaces to create a variation in sentence length for a more natural dialogue effect. | ||
| Line 314: | Line 314: | ||
|      } |      } | ||
|    } |    } | ||
|    // if the string length exceeds the LCD  |    // if the string length exceeds the LCD limit (32 characters) | ||
|    if (dialogue.length() > 32) {   |    if (dialogue.length() > 32) {   | ||
|      dialogue = dialogue.substring(1); // remove the oldest character |      dialogue = dialogue.substring(1); // remove the oldest character | ||
| Line 367: | Line 367: | ||
|    yield(); // buffer ESP - stuff |    yield(); // buffer ESP - stuff | ||
| // LCD  | // show LCD | ||
|    lcd.clear(); |    lcd.clear(); | ||
|    // set cursor to position (column and row) |    // set cursor to position (column and row) | ||
edits