Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Pattern for Arduino LCD Keypad Shield
- // Create custom character: https://omerk.github.io/lcdchargen/
- // String reference: https://www.arduino.cc/en/Reference/StringObject
- // LCD reference: https://www.arduino.cc/en/Reference/LiquidCrystal
- // Stream reference: http://playground.arduino.cc/Main/StreamingOutput
- #include <LiquidCrystal.h>
- #define TIMEOUT 10
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- void setup() {
- // Initialize Serial
- Serial.begin(9600);
- Serial.setTimeout(TIMEOUT);
- // Initialize LCD and special characters
- lcd.begin(16, 2);
- // Generate completely random
- randomSeed(analogRead(1));
- }
- void loop() {
- if (Serial.available() > 0) {
- }
- }
- char readKey() {
- short tolerance = 5;
- short value = analogRead(0);
- short values[] = {639, 408, 255, 99, 0};
- char out[] = {'s', 'l', 'd', 'u', 'r'};
- for (int i = 0; i < 5; i++) {
- if (values[i] - tolerance < value && values[i] + tolerance > value) {
- return out[i];
- }
- }
- return '-';
- }
- String getRandomString(int n) {
- // Awful optimisation, but easy to scale
- char charset[] = "0123456789"
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- String randomString = "";
- for (int i = 0; i < n; i++) {
- randomString += String(charset[random(0, strlen(charset))]);
- }
- return randomString;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement