Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Boilerplate 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
- #define _BYTE(a) _BYTE_CODE(a)
- #define _HEX(a) _BASED(a, HEX)
- #define _DEC(a) _BASED(a, DEC)
- #define _OCT(a) _BASED(a, OCT)
- #define _BIN(a) _BASED(a, BIN)
- template<class T> inline Print &operator <<(Print &stream, T arg) { stream.print(arg); return stream; } struct _BASED { long val; int base; _BASED(long v, int b): val(v), base(b) {}}; struct _BYTE_CODE { byte val; _BYTE_CODE(byte v) : val(v) {} }; inline Print &operator <<(Print &obj, const _BYTE_CODE &arg) { obj.write(arg.val); return obj; } inline Print &operator <<(Print &obj, const _BASED &arg) { obj.print(arg.val, arg.base); return obj; } struct _FLOAT { float val; int digits; _FLOAT(double v, int d): val(v), digits(d) {}}; inline Print &operator <<(Print &obj, const _FLOAT &arg) { obj.print(arg.val, arg.digits); return obj; } enum _EndLineCode { endl }; inline Print &operator <<(Print &obj, _EndLineCode arg) { obj.println(); return obj; }
- #include <LiquidCrystal.h>
- #define TIMEOUT 10
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- byte smiley[8] = {
- B00000,
- B10001,
- B00000,
- B00000,
- B10001,
- B01110,
- B00000,
- };
- typedef struct {
- int number;
- } Object;
- void setup() {
- // Initialize Serial
- Serial.begin(9600);
- Serial.setTimeout(TIMEOUT);
- // Initialize LCD and special characters
- lcd.createChar(0, smiley);
- lcd.begin(16, 2);
- lcd.write((byte)0);
- // Generate completely random
- randomSeed(analogRead(1));
- // Split string
- String t = "a b c d e";
- String splited[5];
- int len;
- splitString(splited, &len, t, " ");
- for (int i = 0; i < len; i++) {
- lcd.write(String(i+1).c_str());
- lcd.write(splited[i].c_str());
- }
- }
- 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;
- }
- void splitString(String *result, int *len, String source, String delimiter) {
- int i = 0;
- int endOfString;
- while ((endOfString = source.indexOf(delimiter)) > 0) {
- result[i++] = source.substring(0, endOfString);
- source.remove(0, endOfString + 1);
- }
- result[i++] = source;
- *len = i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement