How does this work? First, SquareWear 2.0 has a built-in buzzer, so it can already make sound. Next, touch sensing is detected in software. It basically exploits the principle of capacitive sensing: every time you touch an Arduino pin, it slightly alters the capacitance of the pin. This change of capacitance can be detected using a variety of methods. The simplest is to set the pin to digital input mode, and turn on the internal pull-up resistor. This will start charging the capacitor. By detecting the time it takes to charge the capacitor, you can infer the capacitance, and in turn tell if a finger touch has occurred on the pin. That’s it! Because SquareWear maps out available pins to large pin pads, this makes it particularly well-suited for touch sensing.
So I wrote a quick demo as a proof-of-concept. First, I found a function that implements the capacitive sensing from the Arduino playground website. It basically returns a touching sensing value, which can then be compared to a threshold. You may need to adjust the threshold to increase or decrease the sensitivity. The demo scans through all 12 pins available on the SquareWear 2.0 and plays a tone for 125 milliseconds if a pin touch is detected. As a result, the buzzer makes a chiptune type of sound. The code also uses the on-board pushbutton to switch between three octaves: C3, C4, and C5. The LED will blink when a tone is played.
Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.