I am just trying various things out and learning programming.
I have a matrix of 4x4 switches on a board like this one
http://www.ebay.co.uk/itm/B-Arduino-4x4-Square-Keyboard-with-16-Push-Buttons-Practical-Keyboard-Module-/371131680163?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item56692c05a3
I am trying to write a programme to use it, here is a cut down of my full program to date, it works on its own so everything is included.
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite (2,LOW);
digitalWrite (3,LOW);
if (digitalRead (8) == LOW)
{
pinMode (2, INPUT_PULLUP);
delay (5);
pinMode (3, INPUT_PULLUP);
delay (5);
pinMode(8, OUTPUT);
delay (5);
pinMode(9, OUTPUT);
delay (5);
// pinChange;
delay(5);
digitalWrite (8,LOW);
if (digitalRead (2) == LOW)
{
Serial.println ("S15");
}
if (digitalRead (3) == LOW)
{
Serial.println ("S11");
}
pinMode(8, INPUT_PULLUP);
delay (5);
pinMode(9, INPUT_PULLUP);
delay (5);
pinMode(2, OUTPUT);
delay(5);
pinMode(3, OUTPUT);
delay (5);
}
}
void pinChange()
{
pinMode (2, INPUT_PULLUP);
delay (5);
pinMode (3, INPUT_PULLUP);
delay (5);
pinMode(8, OUTPUT);
delay (5);
pinMode(9, OUTPUT);
delay (5);
}
If I run this, when I press one of the relevant keys I get S11 if I press the other I get S15.
If I comment out the section above the 'pinChange' instruction and clear the '//'s from the pinchange instruction I get the result in the monitor switching between S11 and S15
i.e.
S11
S15
S11
S15
etc.
Can anyone explain what I am doing wrong?