Hi,
I am trying to combine two sketches:
-
Arduino shift out tutorial: http://arduino.cc/en/Tutorial/ShiftOut
-
Arduino keypad 4x4 tutorial: http://learning.grobotronics.com/arduino-keypad-4x4-en.html
It gives few error messages which are a mystery to me, like:
sketch_jul07a:55: error: expected unqualified-id before 'if'
sketch_jul07a:56: error: expected unqualified-id before '{' token
Please help me to debug this...thanks in advance.
#include <Keypad.h>
/*
Shift Register Example
for two 74HC595 shift registers
This sketch turns on each of the LEDs attached to two 74HC595 shift registers,
in sequence from output 0 to output 15.
Hardware:
* 2 74HC595 shift register attached to pins 2, 3, and 4 of the Arduino,
as detailed below.
* LEDs attached to each of the outputs of the shift register
Created 22 May 2009
Modified 23 Mar 2010
by Tom Igoe
}
*/
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
char inputString[2];
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
byte rowPins[ROWS] = {2,3,4,5}; //connect to row pinouts
byte colPins[COLS] = {6,7,8,9}; //connect to column pinouts
int count=0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);}
void loop();
char key = keypad.getKey();
if (key != NO_KEY);
{
Serial.print(key);
count++;
if (count==250)
{
count=0;
}
}
// iterate over the 16 outputs of the two shift registers
for (int thisLed = 0; thisLed < 16; thisLed++) {
// write data to the shift registers:
registerWrite(thisLed, HIGH);
// if this is not the first LED, turn off the previous LED:
if (thisLed > 0) {
registerWrite(thisLed - 1, LOW);
}
// if this is the first LED, turn off the highest LED:
else {
registerWrite(15, LOW);
}
delay(key);
}
// This method sends bits to the shift registers:
// the bits you want to send. Use an unsigned int,
// so you can use all 16 bits:
unsigned int bitsToSend = 0;
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// turn on the next highest bit in bitsToSend:
bitWrite(bitsToSend, whichPin, whichState);
// break the bits into two bytes, one for
// the first register and one for the second:
byte registerOne = highByte(bitsToSend);
byte registerTwo = lowByte(bitsToSend);
// shift the bytes out:
shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}