winka based keyboard

main
JbLb 2 years ago
parent 5bb0992bcc
commit f4006a662b

@ -18,7 +18,6 @@ framework = arduino
lib_deps = lib_deps =
waspinator/AccelStepper@^1.64 waspinator/AccelStepper@^1.64
arduino-libraries/Servo@^1.1.8 arduino-libraries/Servo@^1.1.8
adafruit/Adafruit MPR121@^1.1.1
marcoschwartz/LiquidCrystal_I2C@1.1.2 marcoschwartz/LiquidCrystal_I2C@1.1.2
[env:nano_new] [env:nano_new]
@ -28,5 +27,4 @@ framework = arduino
lib_deps = lib_deps =
waspinator/AccelStepper@^1.64 waspinator/AccelStepper@^1.64
arduino-libraries/Servo@^1.1.8 arduino-libraries/Servo@^1.1.8
adafruit/Adafruit MPR121@^1.1.1
marcoschwartz/LiquidCrystal_I2C@1.1.2 marcoschwartz/LiquidCrystal_I2C@1.1.2

@ -12,7 +12,9 @@
#include <AccelStepper.h> #include <AccelStepper.h>
#include <Servo.h> #include <Servo.h>
#include "charset.h" #include "charset.h"
#include "my_buttons.h" //#include "my_buttons.h"
//#include "new_buttons.h"
#include "vinka_key.h"
#define OOROBOT_VERSION "1.1.2" #define OOROBOT_VERSION "1.1.2"
@ -86,10 +88,17 @@ char buttonsMap[] = {
'-', 0, 'S', 'A', 0, '+', 0, 0, 0, 0, 0, 0 '-', 0, 'S', 'A', 0, '+', 0, 0, 0, 0, 0, 0
}; };
*/ */
/*
char buttonsMap[] = { char buttonsMap[] = {
'C', 0, 'D', '|', 's', 'R','P', 'L', 'G', 0, 'U', '!', 'C', 0, 'D', '|', 's', 'R','P', 'L', 'G', 0, 'U', '!',
'A', 0, 0, 0, 'S', '+' , 0, '-', 0, 0, 0, 0 'A', 0, 0, 0, 'S', '+' , 0, '-', 0, 0, 0, 0
}; };
*/
char buttonsMap[] = {
'G',0,'U','!',0,'R','P','L','C',0,'D','|',0,0,0,0,
0,0,0,0,'S','+',0,'-','A',0,0,0,0,0,0,0
};
Params params = {140, 1430, 100}; Params params = {140, 1430, 100};
int previousMenu = CTRL_MENU; int previousMenu = CTRL_MENU;

@ -0,0 +1,105 @@
#include <Arduino.h>
#include "vinka_key.h"
#include <Wire.h>
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
#define address 0x65
byte error;
int LONG_CLICK_DELAY = 500;
int DEBOUNCING_DELAY = 300;
int lastButtonId = -1;
unsigned long lastClick = 0;
unsigned long lastRawPressed = 0;
// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
void setupButtons()
{
//Wire.beginTransmission(address);
error = Wire.requestFrom(address, 2);
//error = Wire.endTransmission();
if (error != 0){
Serial.println("vinka_keyboard not found, check wiring?");
while (1);
}
Serial.println("vinka keyboard found!");
}
int getPressedButton() {
int b = -1;
unsigned char temp[2];
Wire.requestFrom(address, 2);
for(unsigned char i = 0; Wire.available() > 0; i++)
{
temp[i] = Wire.read();
}
/* if((temp[0]>0)|(temp[1]>0)){
if(temp[0]&0b00000001) Serial.print("1");
if(temp[0]&0b00000010) Serial.print("4");
if(temp[0]&0b00000100) Serial.print("7");
if(temp[0]&0b00001000) Serial.print("*");
if(temp[0]&0b00010000) Serial.print("2");
if(temp[0]&0b00100000) Serial.print("5");
if(temp[0]&0b01000000) Serial.print("8");
if(temp[0]&0b10000000) Serial.print("0");
if(temp[1]&0b00000001) Serial.print("3");
if(temp[1]&0b00000010) Serial.print("6");
if(temp[1]&0b00000100) Serial.print("9");
if(temp[1]&0b00001000) Serial.print("#");
if(temp[1]&0b00010000) Serial.print("A");
if(temp[1]&0b00100000) Serial.print("B");
if(temp[1]&0b01000000) Serial.print("C");
if(temp[1]&0b10000000) Serial.print("D");
Serial.println(" ");
}
*///// Get the currently touched pads
for (uint8_t i=0; i <2; i++){
for (int8_t j=0; j<8; j++){
if(temp[i] & _BV(j)){
b= 8*i + j;
lastRawPressed = millis();
break;
}
if (b>=0) break ;
}
if (b>=0) break;
}
if (b >= 0){
unsigned long currentClick = millis();
if (lastButtonId != b) {
if (currentClick > lastClick + DEBOUNCING_DELAY) {
Serial.println(" Sort");
lastClick = currentClick;
tone(BUZZ, 1000, 50);
lastButtonId = b;
} else {
b = -1;
}
} else {
if (currentClick > lastClick + LONG_CLICK_DELAY) {
Serial.println(" Long");
lastButtonId = b;
b = b + 16;
lastClick = currentClick;
} else {
b = -1;
}
}
} else {
if (millis() - lastRawPressed > 100) {
lastButtonId = -1;
}
}
return b;
}

@ -0,0 +1,8 @@
#ifndef VINKA_KEY
#define VINKA_KEY
#define BUZZ 2 // Buzzer
int getPressedButton();
void setupButtons();
#endif
Loading…
Cancel
Save