Skip to content

modified touch example and wrapper #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,38 @@ void setup() {
Serial.begin(9600);
while (!Serial);

carrier.begin();
//CARRIER_CASE = false;
//Now we can set our custom touch threshold
// First we update all the buttons with the new threshold
// Then we overwrite individually one of them (they can be all set individually too)
carrier.Buttons.updateConfig(threshold);
carrier.Button0.updateConfig(threshold_btn_0);
carrier.begin();
carrier.Buttons.updateConfig(threshold_btn_0);

}

void loop() {
// put your main code here, to run repeatedly:
carrier.Buttons.update();

// Verify your thresholds
if (carrier.Button0.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH0)) {
Serial.println("touching 0");
}

if (carrier.Button1.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH1)) {
Serial.println("touching 1");
}

if (carrier.Button2.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH2)) {
Serial.println("touching 2");
}

if (carrier.Button3.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH3)) {
Serial.println("touching 3");
}

if (carrier.Button4.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH4)) {
Serial.println("touching 4");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void loop() {
//The LED changes to Green its going to be NC (Normally Closed) or Orange to NO (Normally Open)
//Then the middle pad its going to upload the relay status, to confirm both new status

if (carrier.Button0.onTouchDown()) {
if (carrier.Buttons.onTouchDown(TOUCH0)) {
newRelay2 = !newRelay2;
if (newRelay2) {
carrier.leds.setPixelColor(0, c_orange);
Expand All @@ -53,7 +53,7 @@ void loop() {
carrier.leds.show();

}
if (carrier.Button4.onTouchDown()) {
if (carrier.Buttons.onTouchDown(TOUCH3)) {
newRelay1 = !newRelay1;
if (newRelay1) {
carrier.leds.setPixelColor(4, c_orange);
Expand All @@ -63,7 +63,7 @@ void loop() {
carrier.leds.show();
}

if (carrier.Button2.onTouchDown()) {
if (carrier.Buttons.onTouchDown(TOUCH1)) {
carrier.leds.setPixelColor(2, c_orange);
carrier.leds.show();

Expand Down
20 changes: 10 additions & 10 deletions examples/TouchPads/TouchTypes/TouchTypes.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ void loop() {
// polling the sensor for new measure
carrier.Buttons.update();

if (carrier.Button0.onTouchDown()) {
Serial.println("Touched Down Button 1");
if (carrier.Buttons.onTouchDown(TOUCH0)) {
Serial.println("Touched Down Button 0");
}
if (carrier.Button1.onTouchUp()) {
Serial.println("Release Touch Button 2");
if (carrier.Buttons.onTouchUp(TOUCH1)) {
Serial.println("Release Touch Button 1");
}
if (carrier.Button2.onTouchChange()) {
Serial.println("Changed Touch Button 3");
if (carrier.Buttons.onTouchChange(TOUCH2)) {
Serial.println("Changed Touch Button 2");
}
if (carrier.Button3.getTouch()) {
Serial.println("Touching Button 4");
if (carrier.Buttons.getTouch(TOUCH3)) {
Serial.println("Touching Button 3");
}
if (carrier.Button4.getTouch()) {
Serial.println("Touching Button 5");
if (carrier.Buttons.getTouch(TOUCH4)) {
Serial.println("Touching Button 4");
}
delay(20);
}
22 changes: 11 additions & 11 deletions examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void loop() {

//Different types of touches
//When you first touch it
if (carrier.Button0.onTouchDown()) {
Serial.println("Touched Down Button 1");
if (carrier.Buttons.onTouchDown(TOUCH0)) {
Serial.println("Touched Down Button 0");
carrier.leds.setPixelColor(0, 20, 20, 20); // 'Off' pixel at tail
carrier.leds.show(); // Refresh strip
delay(50);
Expand All @@ -32,8 +32,8 @@ void loop() {
}

//When you release it
if (carrier.Button1.onTouchUp()) {
Serial.println("Release Touch Button 2");
if (carrier.Buttons.onTouchUp(TOUCH1)) {
Serial.println("Release Touch Button 1");
carrier.leds.setPixelColor(1, 20, 20, 20); // 'Off' pixel at tail
carrier.leds.show(); // Refresh strip
delay(50);
Expand All @@ -43,8 +43,8 @@ void loop() {
}

//When it detects a change, down or up
if (carrier.Button2.onTouchChange()) {
Serial.println("Changed Touch Button 3");
if (carrier.Buttons.onTouchChange(TOUCH2)) {
Serial.println("Changed Touch Button 2");
carrier.leds.setPixelColor(2, 20, 20, 20); // 'Off' pixel at tail
carrier.leds.show(); // Refresh strip
delay(50);
Expand All @@ -54,8 +54,8 @@ void loop() {
}

//Normal, if it is being pressed
if (carrier.Button3.getTouch()) {
Serial.println("Touching Button 4");
if (carrier.Buttons.getTouch(TOUCH3)) {
Serial.println("Touching Button 3");
carrier.leds.setPixelColor(3, 20, 20, 20); // 'Off' pixel at tail
carrier.leds.show(); // Refresh strip
delay(5);
Expand All @@ -64,8 +64,8 @@ void loop() {
carrier.leds.show(); // Refresh strip
}

if (carrier.Button4.getTouch()) {
Serial.println("Touching Button 5");
if (carrier.Buttons.getTouch(TOUCH4)) {
Serial.println("Touching Button 4");
carrier.leds.setPixelColor(4, 20, 20, 20); // 'Off' pixel at tail
carrier.leds.show(); // Refresh strip
delay(5);
Expand All @@ -77,4 +77,4 @@ void loop() {

Serial.println();
delay(10);
}
}
15 changes: 7 additions & 8 deletions examples/TouchPads/getTouch/getTouch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void setup() {
Serial.begin(9600);
while (!Serial);
// Qtouch initialization
CARRIER_CASE = false;
if (!carrier.begin()) {
Serial.println("Error in sensors initialization!");
while (1);
Expand All @@ -31,20 +30,20 @@ void loop() {
carrier.Buttons.update();

// Checks if new data are available
if (carrier.Button0.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH0)) {
Serial.println("Touching Button 0");
}
if (carrier.Buttons.getTouch(TOUCH1)) {
Serial.println("Touching Button 1");
}
if (carrier.Button1.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH2)) {
Serial.println("Touching Button 2");
}
if (carrier.Button2.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH3)) {
Serial.println("Touching Button 3");
}
if (carrier.Button3.getTouch()) {
if (carrier.Buttons.getTouch(TOUCH4)) {
Serial.println("Touching Button 4");
}
if (carrier.Button4.getTouch()) {
Serial.println("Touching Button 5");
}

}
94 changes: 38 additions & 56 deletions src/Arduino_MKRIoTCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,70 +24,52 @@
//Define on the sketch to use it
bool CARRIER_CASE = false;

MKRIoTCarrier::MKRIoTCarrier(){
//Restart cleaner
//display.fillScreen(ST77XX_BLACK);
//leds.clear();
//leds.show();

MKRIoTCarrier::MKRIoTCarrier() {
}

int MKRIoTCarrier::begin(){
//Display
display.init(240, 240); // Initialize ST7789 screen
pinMode(3,INPUT_PULLUP); // RESET fix

//Default rotation to align it with the carrier
display.setRotation(2);
display.fillScreen(ST77XX_BLACK);

int MKRIoTCarrier::begin() {
//Display
display.init(240, 240);//.begin(true); // Initialize ST7789 screen
pinMode(3,INPUT_PULLUP); // RESET fix

if(!Buttons.customSens){
//Default rotation to align it with the carrier
display.setRotation(2);
display.fillScreen(ST77XX_BLACK);

if(CARRIER_CASE){
TOUCH.setSensorsSensitivity(5u);
}else{
TOUCH.setSensorsSensitivity(100u);
}
}
Buttons.begin(); //init buttons
Buttons.begin(); //init buttons

//init LEDs
leds.begin();
leds.clear();
leds.show();
//init LEDs
leds.begin();
leds.clear();
leds.show();

//PMIC init
PMIC.begin();
PMIC.enableBoostMode();

//Sensors
uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3 ;
//Serial.println(sensorsOK , BIN);
//PMIC init
PMIC.begin();
PMIC.enableBoostMode();

//If some of the sensors are not connected
if(sensorsOK > 0 ){
Serial.println("Error detected!");
if(sensorsOK & 0b0001){
Serial.println("Ambient light sensor is not connected!");
}
if(sensorsOK & 0b0010){
Serial.println("Pressure sensor is not connected!");
}
if(sensorsOK & 0b0100){
Serial.println("IMU is not connected");
}
if(sensorsOK & 0b1000){
Serial.println("Environmental sensor is not connected!");
}
//Sensors
uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3;

//while (true);
return false;
//If some of the sensors are not connected
if(sensorsOK > 0 ){
Serial.println("Error detected!");
if(sensorsOK & 0b0001){
Serial.println("Ambient light sensor is not connected!");
}
if(sensorsOK & 0b0010){
Serial.println("Pressure sensor is not connected!");
}
if(sensorsOK & 0b0100){
Serial.println("IMU is not connected");
}
if(sensorsOK & 0b1000){
Serial.println("Environmental sensor is not connected!");
}
return false;
}

//Its OK if the SD card is not plugged in
if(!SD.begin(SD_CS)){
Serial.println("Sd card not detected");
}
return true;
if(!SD.begin(SD_CS)) {
Serial.println("Sd card not detected");
}
return true;
}
18 changes: 10 additions & 8 deletions src/Arduino_MKRIoTCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enum {
};

class MKRIoTCarrier{
public:
public:
MKRIoTCarrier();
int begin();

Expand All @@ -108,18 +108,20 @@ class MKRIoTCarrier{
MKRIoTCarrier_Buzzer Buzzer = MKRIoTCarrier_Buzzer(BUZZER); //Buzzer, pin 6

//Buttons
MKRIoTCarrier_Qtouch_Manager Buttons = MKRIoTCarrier_Qtouch_Manager();
MKRIoTCarrier_Qtouch Button0 = MKRIoTCarrier_Qtouch(0, &Buttons);
MKRIoTCarrier_Qtouch Button1 = MKRIoTCarrier_Qtouch(1, &Buttons);
MKRIoTCarrier_Qtouch Button2 = MKRIoTCarrier_Qtouch(2, &Buttons);
MKRIoTCarrier_Qtouch Button3 = MKRIoTCarrier_Qtouch(3, &Buttons);
MKRIoTCarrier_Qtouch Button4 = MKRIoTCarrier_Qtouch(4, &Buttons);
MKRIoTCarrierQtouch Buttons = MKRIoTCarrierQtouch();


MKRIoTCarrierQtouch Button0 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH0);
MKRIoTCarrierQtouch Button1 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH1);
MKRIoTCarrierQtouch Button2 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH2);
MKRIoTCarrierQtouch Button3 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH3);
MKRIoTCarrierQtouch Button4 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH4);

//Display
Adafruit_ST7789 display = Adafruit_ST7789(&SPI, TFT_CS, TFT_DC, -1);

//RGB LEDs
Adafruit_DotStar leds = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
private:
private:
};
#endif
Loading