Skip to content

Commit 59ae00b

Browse files
authored
modified touch example and wrapper (#28)
modified touch example and wrapper added Backward compatibility for previous software version
1 parent 11f537d commit 59ae00b

File tree

9 files changed

+181
-199
lines changed

9 files changed

+181
-199
lines changed

examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,38 @@ void setup() {
1313
Serial.begin(9600);
1414
while (!Serial);
1515

16+
carrier.begin();
1617
//CARRIER_CASE = false;
1718
//Now we can set our custom touch threshold
1819
// First we update all the buttons with the new threshold
1920
// Then we overwrite individually one of them (they can be all set individually too)
2021
carrier.Buttons.updateConfig(threshold);
21-
carrier.Button0.updateConfig(threshold_btn_0);
22-
carrier.begin();
22+
carrier.Buttons.updateConfig(threshold_btn_0);
23+
2324
}
2425

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

2930
// Verify your thresholds
30-
if (carrier.Button0.getTouch()) {
31+
if (carrier.Buttons.getTouch(TOUCH0)) {
3132
Serial.println("touching 0");
3233
}
3334

34-
if (carrier.Button1.getTouch()) {
35+
if (carrier.Buttons.getTouch(TOUCH1)) {
3536
Serial.println("touching 1");
3637
}
3738

38-
if (carrier.Button2.getTouch()) {
39+
if (carrier.Buttons.getTouch(TOUCH2)) {
3940
Serial.println("touching 2");
4041
}
4142

42-
if (carrier.Button3.getTouch()) {
43+
if (carrier.Buttons.getTouch(TOUCH3)) {
4344
Serial.println("touching 3");
4445
}
4546

46-
if (carrier.Button4.getTouch()) {
47+
if (carrier.Buttons.getTouch(TOUCH4)) {
4748
Serial.println("touching 4");
4849
}
4950
}

examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void loop() {
4343
//The LED changes to Green its going to be NC (Normally Closed) or Orange to NO (Normally Open)
4444
//Then the middle pad its going to upload the relay status, to confirm both new status
4545

46-
if (carrier.Button0.onTouchDown()) {
46+
if (carrier.Buttons.onTouchDown(TOUCH0)) {
4747
newRelay2 = !newRelay2;
4848
if (newRelay2) {
4949
carrier.leds.setPixelColor(0, c_orange);
@@ -53,7 +53,7 @@ void loop() {
5353
carrier.leds.show();
5454

5555
}
56-
if (carrier.Button4.onTouchDown()) {
56+
if (carrier.Buttons.onTouchDown(TOUCH3)) {
5757
newRelay1 = !newRelay1;
5858
if (newRelay1) {
5959
carrier.leds.setPixelColor(4, c_orange);
@@ -63,7 +63,7 @@ void loop() {
6363
carrier.leds.show();
6464
}
6565

66-
if (carrier.Button2.onTouchDown()) {
66+
if (carrier.Buttons.onTouchDown(TOUCH1)) {
6767
carrier.leds.setPixelColor(2, c_orange);
6868
carrier.leds.show();
6969

examples/TouchPads/TouchTypes/TouchTypes.ino

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ void loop() {
3030
// polling the sensor for new measure
3131
carrier.Buttons.update();
3232

33-
if (carrier.Button0.onTouchDown()) {
34-
Serial.println("Touched Down Button 1");
33+
if (carrier.Buttons.onTouchDown(TOUCH0)) {
34+
Serial.println("Touched Down Button 0");
3535
}
36-
if (carrier.Button1.onTouchUp()) {
37-
Serial.println("Release Touch Button 2");
36+
if (carrier.Buttons.onTouchUp(TOUCH1)) {
37+
Serial.println("Release Touch Button 1");
3838
}
39-
if (carrier.Button2.onTouchChange()) {
40-
Serial.println("Changed Touch Button 3");
39+
if (carrier.Buttons.onTouchChange(TOUCH2)) {
40+
Serial.println("Changed Touch Button 2");
4141
}
42-
if (carrier.Button3.getTouch()) {
43-
Serial.println("Touching Button 4");
42+
if (carrier.Buttons.getTouch(TOUCH3)) {
43+
Serial.println("Touching Button 3");
4444
}
45-
if (carrier.Button4.getTouch()) {
46-
Serial.println("Touching Button 5");
45+
if (carrier.Buttons.getTouch(TOUCH4)) {
46+
Serial.println("Touching Button 4");
4747
}
4848
delay(20);
4949
}

examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ void loop() {
2121

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

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

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

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

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

7878
Serial.println();
7979
delay(10);
80-
}
80+
}

examples/TouchPads/getTouch/getTouch.ino

+7-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ void setup() {
1818
Serial.begin(9600);
1919
while (!Serial);
2020
// Qtouch initialization
21-
CARRIER_CASE = false;
2221
if (!carrier.begin()) {
2322
Serial.println("Error in sensors initialization!");
2423
while (1);
@@ -31,20 +30,20 @@ void loop() {
3130
carrier.Buttons.update();
3231

3332
// Checks if new data are available
34-
if (carrier.Button0.getTouch()) {
33+
if (carrier.Buttons.getTouch(TOUCH0)) {
34+
Serial.println("Touching Button 0");
35+
}
36+
if (carrier.Buttons.getTouch(TOUCH1)) {
3537
Serial.println("Touching Button 1");
3638
}
37-
if (carrier.Button1.getTouch()) {
39+
if (carrier.Buttons.getTouch(TOUCH2)) {
3840
Serial.println("Touching Button 2");
3941
}
40-
if (carrier.Button2.getTouch()) {
42+
if (carrier.Buttons.getTouch(TOUCH3)) {
4143
Serial.println("Touching Button 3");
4244
}
43-
if (carrier.Button3.getTouch()) {
45+
if (carrier.Buttons.getTouch(TOUCH4)) {
4446
Serial.println("Touching Button 4");
4547
}
46-
if (carrier.Button4.getTouch()) {
47-
Serial.println("Touching Button 5");
48-
}
4948

5049
}

src/Arduino_MKRIoTCarrier.cpp

+38-56
Original file line numberDiff line numberDiff line change
@@ -24,70 +24,52 @@
2424
//Define on the sketch to use it
2525
bool CARRIER_CASE = false;
2626

27-
MKRIoTCarrier::MKRIoTCarrier(){
28-
//Restart cleaner
29-
//display.fillScreen(ST77XX_BLACK);
30-
//leds.clear();
31-
//leds.show();
32-
27+
MKRIoTCarrier::MKRIoTCarrier() {
3328
}
3429

35-
int MKRIoTCarrier::begin(){
36-
//Display
37-
display.init(240, 240); // Initialize ST7789 screen
38-
pinMode(3,INPUT_PULLUP); // RESET fix
39-
40-
//Default rotation to align it with the carrier
41-
display.setRotation(2);
42-
display.fillScreen(ST77XX_BLACK);
43-
30+
int MKRIoTCarrier::begin() {
31+
//Display
32+
display.init(240, 240);//.begin(true); // Initialize ST7789 screen
33+
pinMode(3,INPUT_PULLUP); // RESET fix
4434

45-
if(!Buttons.customSens){
35+
//Default rotation to align it with the carrier
36+
display.setRotation(2);
37+
display.fillScreen(ST77XX_BLACK);
4638

47-
if(CARRIER_CASE){
48-
TOUCH.setSensorsSensitivity(5u);
49-
}else{
50-
TOUCH.setSensorsSensitivity(100u);
51-
}
52-
}
53-
Buttons.begin(); //init buttons
39+
Buttons.begin(); //init buttons
5440

55-
//init LEDs
56-
leds.begin();
57-
leds.clear();
58-
leds.show();
41+
//init LEDs
42+
leds.begin();
43+
leds.clear();
44+
leds.show();
5945

60-
//PMIC init
61-
PMIC.begin();
62-
PMIC.enableBoostMode();
63-
64-
//Sensors
65-
uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3 ;
66-
//Serial.println(sensorsOK , BIN);
46+
//PMIC init
47+
PMIC.begin();
48+
PMIC.enableBoostMode();
6749

68-
//If some of the sensors are not connected
69-
if(sensorsOK > 0 ){
70-
Serial.println("Error detected!");
71-
if(sensorsOK & 0b0001){
72-
Serial.println("Ambient light sensor is not connected!");
73-
}
74-
if(sensorsOK & 0b0010){
75-
Serial.println("Pressure sensor is not connected!");
76-
}
77-
if(sensorsOK & 0b0100){
78-
Serial.println("IMU is not connected");
79-
}
80-
if(sensorsOK & 0b1000){
81-
Serial.println("Environmental sensor is not connected!");
82-
}
50+
//Sensors
51+
uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3;
8352

84-
//while (true);
85-
return false;
53+
//If some of the sensors are not connected
54+
if(sensorsOK > 0 ){
55+
Serial.println("Error detected!");
56+
if(sensorsOK & 0b0001){
57+
Serial.println("Ambient light sensor is not connected!");
58+
}
59+
if(sensorsOK & 0b0010){
60+
Serial.println("Pressure sensor is not connected!");
61+
}
62+
if(sensorsOK & 0b0100){
63+
Serial.println("IMU is not connected");
64+
}
65+
if(sensorsOK & 0b1000){
66+
Serial.println("Environmental sensor is not connected!");
8667
}
68+
return false;
69+
}
8770

88-
//Its OK if the SD card is not plugged in
89-
if(!SD.begin(SD_CS)){
90-
Serial.println("Sd card not detected");
91-
}
92-
return true;
71+
if(!SD.begin(SD_CS)) {
72+
Serial.println("Sd card not detected");
73+
}
74+
return true;
9375
}

src/Arduino_MKRIoTCarrier.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ enum {
8989
};
9090

9191
class MKRIoTCarrier{
92-
public:
92+
public:
9393
MKRIoTCarrier();
9494
int begin();
9595

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

110110
//Buttons
111-
MKRIoTCarrier_Qtouch_Manager Buttons = MKRIoTCarrier_Qtouch_Manager();
112-
MKRIoTCarrier_Qtouch Button0 = MKRIoTCarrier_Qtouch(0, &Buttons);
113-
MKRIoTCarrier_Qtouch Button1 = MKRIoTCarrier_Qtouch(1, &Buttons);
114-
MKRIoTCarrier_Qtouch Button2 = MKRIoTCarrier_Qtouch(2, &Buttons);
115-
MKRIoTCarrier_Qtouch Button3 = MKRIoTCarrier_Qtouch(3, &Buttons);
116-
MKRIoTCarrier_Qtouch Button4 = MKRIoTCarrier_Qtouch(4, &Buttons);
111+
MKRIoTCarrierQtouch Buttons = MKRIoTCarrierQtouch();
112+
113+
114+
MKRIoTCarrierQtouch Button0 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH0);
115+
MKRIoTCarrierQtouch Button1 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH1);
116+
MKRIoTCarrierQtouch Button2 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH2);
117+
MKRIoTCarrierQtouch Button3 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH3);
118+
MKRIoTCarrierQtouch Button4 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH4);
117119

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

121123
//RGB LEDs
122124
Adafruit_DotStar leds = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
123-
private:
125+
private:
124126
};
125127
#endif

0 commit comments

Comments
 (0)