winka based keyboard

main
JbLb 2 years ago
parent 5bb0992bcc
commit f4006a662b

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

@ -4,7 +4,7 @@
Get the following libraries (using the Arduino IDE library manager)
- **AccelStepper** v1.57.1 by Mike McCauley
- **LiquidCrystal I2C** v1.1.2 by Frank de Brabander
*/
#include <EEPROM.h>
#include <Wire.h>
@ -12,7 +12,9 @@
#include <AccelStepper.h>
#include <Servo.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"
@ -86,10 +88,17 @@ char buttonsMap[] = {
'-', 0, 'S', 'A', 0, '+', 0, 0, 0, 0, 0, 0
};
*/
/*
char buttonsMap[] = {
'C', 0, 'D', '|', 's', 'R','P', 'L', 'G', 0, 'U', '!',
'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};
int previousMenu = CTRL_MENU;
@ -127,7 +136,7 @@ void setup() {
loadParams();
setupButtons();
Serial.println(F("Setup"));
tone(BUZZ, 1047, 100);
delay(150);
tone(BUZZ, 1319, 100);
@ -287,7 +296,7 @@ void actionButtonForScreen(char button) {
break;
case 'B' :
case 'a' :
case 'c' :
case 'c' :
case 'r' :
case 'E' :
case 'U' :
@ -439,7 +448,7 @@ void updateScreen() {
if (selectedLine==2) {
stepIdx=2;
turnIdx=2;
lineIdx=0;
lineIdx=0;
}
if (stepIdx<2) {
lcd.setCursor(0, stepIdx);
@ -448,7 +457,7 @@ void updateScreen() {
lcd.print(F("."));
lcd.print(mm);
lcd.print(F("cm"));
}
}
if (turnIdx<2) {
lcd.setCursor(0, turnIdx);
lcd.print(F(" 1/4Tour:"));
@ -461,7 +470,7 @@ void updateScreen() {
lcd.print(params.lineSteps);
lcd.print(F("pas"));
}
lcd.setCursor(0, selectedLine%2);
lcd.print("\6");
#ifdef HAVE_BLUETOOTH
@ -540,7 +549,7 @@ boolean launchNextCommand() {
num_of_cmd++;
delay(stepDelay);
// lcd.setBacklight(LOW);
enableMotors();
char command = cmd[commandLaunched];
@ -578,7 +587,7 @@ boolean launchNextCommand() {
moveServo(0);
break;
case '|' :
Serial.println(F("pen up"));
Serial.println(F("pen up"));
moveServo(30);
break;
case 'c' :
@ -588,7 +597,7 @@ boolean launchNextCommand() {
if (stepSize==1) {
reverseOrientation=true;
} else {
reverseOrientation=false;
reverseOrientation=false;
}
break;
case 'a' :
@ -680,7 +689,7 @@ boolean isCommandTerminated() {
}
}
*/
stepper2.setSpeed(MAX_STEPPER_SPEED);
stepper2.setSpeed(MAX_STEPPER_SPEED);
stepper1.setSpeed(MAX_STEPPER_SPEED);
steps1 = stepper1.distanceToGo();

@ -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