This is cobbled from several samples and reads a keypad and displays the button pressed on the oled screen. It is just a test code to figure out several things for a bigger project.
The last line:
oled.drawString(6,40,(key),RED,BLACK);
is where I'm having problems. it is supposed to show the key being pressed (full sketch code below).
buit doesn't compile. need to have this test working so I can display variables (on the final build I need to display variables read from sensors)
// ********************* test build 1a skreen and keypad
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {39, 49, 47, 43}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {41, 37, 45}; //connect to the column pinouts of the keypad
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
OLED oled(pin_cs, pin_dc, pin_reset);
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
char key = keypad.getKey();
Serial.print("init...");
oled.begin();
oled.selectFont(SystemFont5x7);
oled.drawString(6,70,F("TEST System 5x7\nOn Two Lines"),RED,BLACK);
oled.drawString(6,40,(key),RED,BLACK);
}
It appears that the value in key from
char key = keypad.getKey();
was in ascii not the actual number I was expecting (ie 1,2...) that the oled.drawstring could handle.
I have tested this three ways:
-
defined a char test[] = "censored word"; character string at the top and inserted (test) in place of the text - that appeared.
-
if (key) had a line that occured if a button was pressed
-
if ( key == 49) .......... if ( key == 50)...... (see code below) using the same screen co-ordinates this showed the word "one" or "two" based on the key pressed
void loop() {
// put your main code here, to run repeatedly:
char key = keypad.getKey();
if( key == 49)
{
oled.drawString(6,120,"one",RED,BLACK);
}
else if( key == 50)
{
oled.drawString(6,120,"two",RED,BLACK);
}
if (key){
oled.drawString(6,100,(test),RED,BLACK);
}
oled.drawString(6,80,"y80 System 5x7\nOn Two Lines",RED,BLACK);
Also I couldn't get a sensor reading to appear untill I used the oled textbox function
// ********************* test build 1a skreen and keypad
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char fuck[] = "shit";
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {39, 49, 47, 43}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {41, 37, 45}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox text(oled);
char test[] = "doushbag";
char testicle[] = "a";
int ldr = 10;
int value = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
oled.begin();
oled.selectFont(SystemFont5x7);
pinMode (ldr,INPUT);
}
void loop() {
value = analogRead(ldr);
// put your main code here, to run repeatedly:
char key = keypad.getKey();
if( key == 49)
{
text.println (value);
}
else if( key == 50)
{
text.println ("two");
}
};