Merry Xmas Paul !
Quote
If you convert the 19 integers to a string, how will you tell one value from another? This string contains three values - "1456732". Can you tell what the three values are?
thats why I mentioned comma separated variables.
I didn't post the whole code because I havn't got this bit working with a days worth of different ideas, but I will post the rest below, the problem is with sending the array " blockChar " that I need to send . ( I only need to send 19 of them )
The array is indexed to the block number 1-32 of the LCD display.
The whole code is work in progress, I will change the ifs to case type selection later.
I can display it on the LCD display with no problem, and with my previous RF modules ( 4 times the price ) I could have sent it with VirtualWire, but I am trying to master these more intelligent ones.
In retrospect this isn't the ideal project to learn this but I don't have a choice.
There are 5 buttons to set the two 8 digit team names on a scoreboard, and a preset 2 digit period minutes.
These are displayed on an LCD, the remote goes into sleep, and the backlight goes of after a few seconds of inactivity, I still have to sort out what to switch off on the LCD for sleep, and some other minor functions.
The S button sends the data, the L and R buttons move the cursor left and right, and the Up and Down buttons scroll thorough the charachters ( fast forward when held down )
The code as requested is below ( I have had to split it into 2 posts as it was over the limit of characters )
#include <SPI.h>
#include <RF22.h>
#include <Keypad.h>
#include <LiquidCrystal.h> // we need this library for the LCD commands
#include <avr/sleep.h> // powerdown library
#include <avr/interrupt.h> // interrupts library
// Singleton instance of the radio
RF22 rf22;
char key;
int botRow;
int backlightPin = 14;
int pin3 = 3; // Int1 interuppt pin
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
long sleep_count = 0; // flag/counter to tell us to go sleep
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int button; // integer of button ascii number
int blinkLoop; // loopcount for the cursor blinking
char chars [] = {
'_','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I',
'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','.','?' };
uint8_t blockChar [32]; // the actual character for each block to display and send //8888888888888888888888888 was char
int q [32 ];
char msg [19]; // the two 8 char teamnames and the intital minutes plus PIN
int PIN = 101; // for first takealot text remote
/////////////////////////////////////// keypad settings ////////////////////
const byte ROWS = 2; // two rows
const byte COLS = 3; // three columns
char keys[ROWS][COLS] = {
{
'C','U','L' }
, // row 1 // CLEAR, UP, LEFT
{
'S','R','D' }
, // row 2 // SEND , RIGHT , DOWN
};
byte rowPins[ROWS] = {
19, 18 };
byte colPins[COLS] = {
15,16,17}; // Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
////////////////////////////////////////////////////////////////////////////////
LiquidCrystal lcd(4,5,6,7,8,9); // define our LCD and which pins to user
int block ; // 0 - 31 character position numbers 0 - 15 top row, 16 - 32
unsigned long previousMillis = 0;
//**************************************************************new interrupt
// * Name: pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin3Interrupt()
{
/* This brings us back from sleep. */
}
//***************************************************************
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit
//lcd.clear(); // this clears the LCD. You can use this at any time
Serial.println(" setup");
for ( int x = 0; x <=31; x++ ) { // clears all the blocks to underscore which will show as blank on board
blockChar [x] = 0 ;
}
lcd.display(); //enable lcd display
lcd.clear();
blinkLoop = 0;
resethome (); // clears display and zeros cursor
block = 0; // start at block 0 top left
for ( int x = 0; x <=31; x++ ) { // clear all values for all blocks
q [x] = 0 ;
}
pinMode (backlightPin , OUTPUT );
lcd.setCursor(10,0);
lcd.print("min="); // prints the period minutes on top right, and returns cursor to 1,0
lcd.setCursor(1,0);
block = 1;
if (!rf22.init())
Serial.println("RF22 init failed");
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
if (!rf22.setFrequency(434.0))
Serial.println("setFrequency failed");
if (!rf22.setModemConfig(RF22::GFSK_Rb2Fd5))
Serial.println("setModemConfig failed");
}
void loop()
{
if (sleep_count>100000){ // check if we should go to sleep because of "time" --> Try shorter versions of this
sleep_count=0; // turn it off for when we wake up
Serial.println("Sleep"); // for debug only
digitalWrite(15, LOW);// set the columns low before sleeping, otherwise Keypad leaves them high and Rows have nothing to pull low.
digitalWrite(16,LOW);
digitalWrite(17, LOW);
digitalWrite(backlightPin, LOW);
Serial.println(" backlight off ");
enterSleep(); // call Sleep function to put us out
// THE PROGRAM CONTINUEs FROM HERE after waking up in enterSleep()
}
blinkLoop++; // blink cursor so shows difference between E and F for example
if (blinkLoop > 500) {
lcd.cursor() ;
}
else {
lcd.noCursor() ;
}
if (blinkLoop > 1000) {
blinkLoop = 0;
}
char key = keypad.getKey(); // reading the keypad
if(key) { // same as if(key != NO_KEY)- did something change?
Serial.print("key read =");
Serial.println(key);
button = key; // integer version of ascii
checkbutton (); // actions for each key
sleep_count = 0;
}
sleep_count ++;
if ( keypad.getState() == HOLD )
{
Serial.print("key held =");
Serial.println(key);
if (( millis() - 250) > previousMillis )
{
previousMillis = millis();
checkbutton (); // actions for each key
}
}
}
void resethome () {
lcd.clear();
lcd.display();
lcd.setCursor(10,0);
lcd.print("min="); // prints the period minutes on top right, and returns cursor to 1,0
lcd.setCursor(1,0);
block = 1;
}
void checkbutton () {
Serial.print("key pressed = ");
Serial.println(button);
if ( button == 67 ) { // key = C or ascii 67 Clear
Serial.print("key ch = ");
Serial.println(key);
resethome () ;
Serial.println("key check = cancel C ");
}
//*****************************************************************************
if ( button == 83 ) {// key = S or ascii 83 Send
Serial.print("key check =send S "); // still got to write this bit
}
//******************************************************************************
if ( button == 76 ) { // key = L or ascii 85 LEFT
Serial.print("key check = L cursor left ");
block = block--;
if ( block < 1 ) {
block = 24 ;
}
if ( block ==13 ) {
block =8;
}
if ( block ==16 ) {
block =15;
}
Serial.print("block ");
Serial.print(block);
if ( block >15 ) {
// botRow = block - 16 ;
lcd.setCursor(block-16 ,1);
}
else {
lcd.setCursor(block,0);
}
}
//*****************************************************************************
if ( button == 82 ) { // key = R or ascii 82
Serial.print("key check = R cursor right ");
block = block++;
if ( block > 24 ) {
block = 1 ;
}
if ( block ==9 ) {
block = 14 ;
}
if ( block ==16 ) {
block = 17 ;
}
Serial.print("block ");
Serial.print(block);
if ( block >15 ) {
// botRow = block - 16 ;
lcd.setCursor(block-16 ,1);
}
else {
lcd.setCursor(block,0);
}
}