This commit is contained in:
PJB123456
2023-06-12 17:33:54 +08:00
parent ce4f5e7994
commit ea50c6f954
135 changed files with 8767 additions and 10 deletions
@@ -10,7 +10,8 @@ class ADCDevice {
public int cmd = 0;
public I2C i2c;
public ADCDevice() {
i2c = new I2C(I2C.list()[0]);
//Note that if you are running on a version 1 Raspberry Pi, you need to change the subscript index to 0.
i2c = new I2C(I2C.list()[1]);
}
public boolean detectI2C(int addr) {
@@ -10,7 +10,8 @@ class ADCDevice {
public int cmd = 0;
public I2C i2c;
public ADCDevice() {
i2c = new I2C(I2C.list()[0]);
//Note that if you are running on a version 1 Raspberry Pi, you need to change the subscript index to 0.
i2c = new I2C(I2C.list()[1]);
}
public boolean detectI2C(int addr) {
@@ -10,7 +10,8 @@ class ADCDevice {
public int cmd = 0;
public I2C i2c;
public ADCDevice() {
i2c = new I2C(I2C.list()[0]);
//Note that if you are running on a version 1 Raspberry Pi, you need to change the subscript index to 0.
i2c = new I2C(I2C.list()[1]);
}
public boolean detectI2C(int addr) {
@@ -10,7 +10,8 @@ class ADCDevice {
public int cmd = 0;
public I2C i2c;
public ADCDevice() {
i2c = new I2C(I2C.list()[0]);
//Note that if you are running on a version 1 Raspberry Pi, you need to change the subscript index to 0.
i2c = new I2C(I2C.list()[1]);
}
public boolean detectI2C(int addr) {
@@ -0,0 +1,101 @@
/*
******************************************************************************
* class SingleKey
* Author Freenove (http://www.freenove.com)
* Date 2016/08/27
******************************************************************************
* Brief
* This class is used to get a single button key value (GPIO numbering)
******************************************************************************
* Copyright
* Copyright © Freenove (http://www.freenove.com)
* License
* Creative Commons Attribution ShareAlike 3.0
* (http://creativecommons.org/licenses/by-sa/3.0/legalcode)
******************************************************************************
*/
int keyValue = -1;
class SingleKey {
final int IDLE = 0,
PRESSED = 1,
HOLD = 2,
RELEASED = 3;
int btnState = IDLE;
boolean isPressed = false;
boolean isHold = false;
long holdTimer = 0;
final int holdTime = 100;
boolean changeState = false;
int lastButtonIOState = GPIO.HIGH;
int buttonIOState=GPIO.HIGH;
int nowButtonState;
boolean buttonChanged = false;
int lastChangeTime;
int decounceTime = 20;
int pin;
public SingleKey(int Pin) {
pin = Pin;
GPIO.pinMode(pin, GPIO.INPUT);
}
void keyScan() {
nowButtonState =GPIO.digitalRead(pin);
if (nowButtonState != lastButtonIOState) {
lastChangeTime = millis();
}
if (millis() - lastChangeTime > decounceTime) {
if (buttonIOState != nowButtonState) {
buttonIOState = nowButtonState;
changeState = true;
if (buttonIOState == GPIO.LOW) {
//btnState = PRESSED;
//keyValue = pin;
//println("Key is Pressed !! ");
} else if (buttonIOState == GPIO.HIGH) {
//println("Key is Released !! ");
}
}
}
switch(btnState) {
case IDLE:
if (changeState) {
changeState = false;
btnState = PRESSED;
holdTimer = millis();
keyValue = pin;
isPressed = true;
}
break;
case PRESSED:
if (millis() - holdTimer > holdTime) {
btnState = HOLD;
keyValue = pin;
isPressed = true;
isHold = true;
} else if (changeState) {
changeState = false;
btnState = RELEASED;
} else {
keyValue = -1;
isPressed = false;
}
break;
case HOLD:
keyValue = pin;
isPressed = true;
isHold = true;
if (changeState) {
changeState = false;
btnState = RELEASED;
}
break;
case RELEASED:
keyValue = -1;
isPressed = false;
isHold = false;
btnState = IDLE;
break;
}
lastButtonIOState = nowButtonState;
}
}
@@ -5,10 +5,12 @@
* modification: 2020/03/11
*****************************************************/
import processing.io.*;
//Create a object of class ADCDevice
//Create an object of class ADCDevice
ADCDevice adc = new ADCDevice();
int cx, cy, cd, cr; //define the center point,side length & half.
int cx, cy, cd, cr; //define the center point, side length & half.
int buttonPin = 18;
SingleKey skey = new SingleKey(buttonPin);
void setup() {
size(640, 360);
if (adc.detectI2C(0x48)) {
@@ -28,7 +30,13 @@ void draw() {
int x=0, y=0, z=0;
x = adc.analogRead(0); //read the ADC of joystick
y = adc.analogRead(1); //
z = adc.analogRead(2);
//z = adc.analogRead(2);
skey.keyScan(); //key scan
if (skey.isPressed) { //key is pressed
z=0;
} else {
z = 255;
}
background(102);
titleAndSiteInfo();
fill(0);