Ho trovato questo codice (gia leggermente modificato x le mie esigenze) ma da sistemare (per le porte di arduino per la tastiera 4x4), ho visto che e
meglio utilizzare un display 2x16 compatibile con Hitachi HD44780 driver con relativo potenziometro (al momento escludo il pannello a led 1x10, lo vedro quando sara` tutto ok su questo display, successivamente vorrei gestire i 2 display in maniera tale che venga visualizzato lo stesso messaggio su entrambi).
Questi sono i link:
e questo il codice:
/*
// include the library code:
#include <LiquidCrystal.h>
// debug stuff
boolean debug = true;
// communication stuff
const int MAX_CMD_LEN = 128;
char cmd[MAX_CMD_LEN];
boolean connected = false;
long pingWait = 0; // this is the counter to send the
ping
const long pingSend = 50000L; // when to send the ping
long pingCount = 0; // how many times this has
received a ping.
long pongCount = 0; // how many times this has
received a pong.
// initialize the library with the numbers of the
interface pins
LiquidCrystal lcd(12,11,5,4,3,2);
// keypad stuff
int kppins[] = {12,11,10,9,0,1,2,3};
int keyWait = 0;
int keyDelay = 100; // If the last time this key was
pressed < this then ignore
char* key[]={"1","2","3","A",
"4","5","6","B",
"7","8","9","C",
"CLEAR","0"," ","D"};
// noise maker stuff
int tone = 195;
// led stuff
int ledPin = 13;
void setup() {
// setup communications stuff
Serial.begin(9600);
// keypad pins
pinMode(kppins[0], OUTPUT);
pinMode(kppins[1], OUTPUT);
pinMode(kppins[2], OUTPUT);
pinMode(kppins[3], OUTPUT);
// set up the LCD
lcd.begin(16, 2); // 16 columns and 2 rows
// beeper
pinMode(8, OUTPUT);
}
void loop() {
if ( Serial.available() != 0 ) {
// something is on the line so read it
readln(cmd);
if ( debug && strcmp(cmd,"") != 0 ) {
Serial.print("Arduino got ");
Serial.print(cmd);
Serial.println("");
}
}
if (strcmp(cmd,"") == 0 && pingWait > pingSend) {
// haven't sent or received any thing for a while
so do a ping to see if anything is (still) there.
Serial.println("ping");
pingWait = 0;
} else if (strcmp(cmd, "pong") == 0) {
// received a pong response so something is
connected
connected = true;
pingWait = 0;
pongCount++;
} else if (strcmp(cmd, "ping") == 0) {
// something wants to know if the arduino is still
here. I must be connected. send a pong back.
Serial.println("pong");
connected = true;
pingWait = 0;
pingCount++;
}
cmd[0]= NULL; // what ever the command was reset it
// see if the keyboard has been pressed
int newVal = checkKeypad();
if ( newVal > -1 && keyWait > keyDelay ) {
keyBeep();
// now do something
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("");
lcd.print(key[newVal]);
keyWait = 0;
}
pingWait++;
keyWait ++;
}
void readln( char buffer[] ) {
char c;
int i = 0;
int quiet = 0;
while( true ) {
if ( Serial.available() ) {
quiet = 0;
c = Serial.read();
if ( c == 13 ) { // carriage return
Serial.read(); // line feed
break;
}
buffer[i++] = c;
if ( i == (MAX_CMD_LEN-1) ) break;
} else {
if ( quiet > 10000 ) break;
quiet ++;
}
delay(10); // short delay
}
buffer *= NULL; *
}
void keyBeep() {
- // beep and flash*
- digitalWrite(ledPin, HIGH); *
_ for (long i = 0; i < 80000L; i += tone * 2.5) {_
- digitalWrite(8, HIGH);*
- delayMicroseconds(tone);*
- digitalWrite(8, LOW);*
- delayMicroseconds(tone);*
- }*
- digitalWrite(ledPin, LOW);*
}
int checkKeypad() {
- int rtn = -1;*
- for ( int i = 0; i < 4; i++ ) {*
_ digitalWrite(kppins*,HIGH);_
_ for (int j = 0; j < 4; j ++) {_
_ int pushed = map( analogRead(j), 0, 1024, 0, 2*_
);
* if ( pushed == 1 ) {*
* rtn = (i<<2) + j;*
* }*
* }*
_ digitalWrite(kppins*,LOW);
}
return rtn;
}*
Qualche consiglio su che porte impostare (collegamenti e nel codice) x la tastierina?_