Journal 2017/04/25

arduino_official_logo__

My previous problem of not being able to upload the code was solved when the drivers for the nanoboard were installed.

This allowed me to successfully upload the code to the nanoboard.

 

Now that Ive uploaded the code to the nanoboard I need to wait for the wires to come in, in order to solder them to the keyswitches

I used this code as a test.

#include <Bounce2.h>

//Pins
#define led1 2 //led 1
#define led1n 3 //negative so wiring can be neat
#define led2 5 //led 2
#define led2n 4 //negative
#define ledL 13 //led L is on pin 13 on a uno
#define key1 6 //button pin 1
#define key2 7 //button pin 2
#define key1v 29// Letter Z, values from http://www.win.tue.nl/~aeb/linux/kbd/scancodes-14.html
#define key2v 27// Letter X, v for value
//Alternate keys:
//#define key1v 6// Letter C
//#define key2v 25// Letter V

//states
boolean state1 = true;   //if button1 has not been pushed
boolean state2 = true;   //if button2 has not been pushed

//creating bounce objects
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();

void setup()
{
Serial.begin(9600);

//So you don’t need a resistor
pinMode(key1, INPUT_PULLUP);
pinMode(key2, INPUT_PULLUP);

//attaching the buttons to the bouncer
debouncer1.attach(key1);
debouncer2.attach(key2);

//time in Msec to wait to remove bounces, 3-8 Msec is good
debouncer1.interval(3);
debouncer2.interval(3);

pinMode(led1, OUTPUT);
pinMode(led1n, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led2n, OUTPUT);
pinMode(ledL, OUTPUT); //LED L onboard

digitalWrite(led1n, LOW);//ground
digitalWrite(led2n, LOW);
digitalWrite(ledL, LOW);
}

void loop() {
//check button push state
debouncer1.update();
debouncer2.update();

if (debouncer1.read() == LOW & state1) { // Send keypress
buf[2] = key1v;//starts from array 2
Serial.write(buf, 8);
digitalWrite(led1, HIGH);
state1 = false;
}
if (debouncer1.read() == HIGH & !state1) { // Release key
buf[2] = 0;
Serial.write(buf, 8);
digitalWrite(led1, LOW);
state1 = true;
}

if (debouncer2.read() == LOW & state2) { // Send keypress
buf[3] = key2v;
Serial.write(buf, 8);
digitalWrite(led2, HIGH);
state2 = false;
}
if (debouncer2.read() == HIGH & !state2) { // Release key
buf[3] = 0;
Serial.write(buf, 8);
digitalWrite(led2, LOW);
state2 = true;
}
}

 

I will end up editing it in order to better fit my keypad

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s