Overview

This program demonstrates usage of the GR-COTTON board's star-shaped touch sensors.


Preparation

You will need a GR-COTTON board and a USB cable (Micro B type).

Make sure the white jumper on the reverse side of GR-COTTON is moved to the “3V3 USB” side. If it is set to the BATT side, remove and reinsert it into the USB side.


Using the Touch Sensors to Activate the LED

The sample below programs the LED to light up when the GR-COTTON touch sensors are pressed.

Additionally: A6 and A7 are pulled up by significant 10MΩ resistance, but when the sensor is touched, the other side may also respond. Therefore, although the sample below controls the A6 and A7 touch sensors separately, A7 may respond even when only A6 alone is touched, causing red and blue LED lights to activate at the same time.


#include <arduino.h>

void setup() {
  pinMode(22, OUTPUT); //red led
  pinMode(24, OUTPUT); //blue led
  digitalWrite(22, HIGH);
  digitalWrite(24, HIGH);
}
    
void loop() {
  if(analogRead(A6) < 800){
    digitalWrite(22, LOW);
  } else {
    digitalWrite(22, HIGH);
  }
 
  if(analogRead(A7) < 800){
    digitalWrite(24, LOW);
  } else {
    digitalWrite(24, HIGH);
  }
   
}


Conserving Power Until Touch Sensor Activation

In the previous sample, the MCU continues to function until the touch sensor is pressed. In this sample below, however, the SNOOZE mode enables power conservation until the touch sensor is pressed.

The two samples appear similar at first glance, but there are differences, such as the battery life. Only the A6 touch sensor responds. This function is unique to GR-COTTON and GR-KURUMI.


#include <arduino.h>

void setup() {
  setPowerManagementMode(PM_SNOOZE_MODE, 0, 800);    
  pinMode(23, OUTPUT); //green led
  digitalWrite(23, HIGH);
}
   
void loop() {
  analogRead(A6); // into snooze until touch   
  digitalWrite(23, LOW);
  delay(100);
  digitalWrite(23, HIGH);
   
}