MCN 2017 Workshop
Welcome to the workshop. We’ll have lots of fun working with Arduino today.
Parts
A quick list of the parts in our kit:
Learn more about the Circuit Playground Classic here. We chose the classic for our class, because the Express does not yet have full support.
Installation
Before we use our kits, we need to install some pieces. Sometimes this part can be a bit tricky, depending on your computer. Follow the steps below.
- If you have Windows, install the drivers.
- Download the Arduino IDE.
- Install the Circuit Playground library via the Library Manager. Stop when you get to the section titled “Run the Demo.” We’ll go through those steps together.
Load our First Programs
Together, let’s load our first programs. Follow the steps you saw before to run the demo. Then, load the blink program viaFile >> Examples >> Adafruit Circuit Playground >> Hello_Circuit Playground >> Hello_Blink.
Try Other Programs
Next, try the other Circuit Playground programs that came with the library. File >> Examples >> Adafruit Circuit Playground >> Hello_Circuit Playground >>. See what they do. When you’re finished with those, jump up to some of the others like Birthday_Candles or FidgetSpinner.
Wire a Circuit
Now, we’ll break out of the box and build our own circuit using the LED sequins and alligator clips. First, let’s test the LEDs using just power, no code. Follow the diagram below:
Next, let’s use code to control the external LED. Change the circuit, and upload the new code.
#include <Adafruit_CircuitPlayground.h> int d = 250; // how long to delay in the blink int ledPin = 6; // which pin is connected to the led? void setup() { CircuitPlayground.begin(); pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); delay(d); digitalWrite(ledPin, LOW); delay(d*2); }
For an advanced code option, combine the blink with a button press.
#include <Adafruit_CircuitPlayground.h> // learn more about state changes here: https://www.arduino.cc/en/Tutorial/StateChangeDetection?from=Tutorial.ButtonStateChange // this constant won't change: const int buttonPin = 2; // the pin that the pushbutton is attached to const int ledPin = 6; // the pin that the LED is attached to // Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button void setup() { CircuitPlayground.begin(); // initialize the LED as an output: pinMode(ledPin, OUTPUT); // initialize serial communication: Serial.begin(9600); } void loop() { // read the pushbutton input pin: buttonState = CircuitPlayground.leftButton(); // compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH) { // if the current state is HIGH then the button went from off to on: buttonPushCounter++; Serial.println("on"); Serial.print("number of button pushes: "); Serial.println(buttonPushCounter); } else { // if the current state is LOW then the button went from on to off: Serial.println("off"); } // Delay a little bit to avoid bouncing delay(50); } // save the current state as the last state, for next time through the loop lastButtonState = buttonState; // turns on the LED every four button pushes by checking the modulo of the // button push counter. the modulo function gives you the remainder of the // division of two numbers: if (buttonPushCounter % 2 == 0) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } }
Remix Programs
Try remixing programs. Maybe try using the capacitive touch sensors.
Here is one where I combined the light sensor and the speaker to make a theremin.
/* Original idea from Adafruit Arduino - Lesson 10. Pseudo Thermin https://learn.adafruit.com/adafruit-arduino-lesson-10-making-sounds/arduino-code */ #include <Adafruit_CircuitPlayground.h> int reading; // store light sensor reading const int minPitch = 200; const int maxPitch = 6000; void setup() { Serial.begin(9600); CircuitPlayground.begin(); } void loop() { // read the light sensor reading = CircuitPlayground.lightSensor(); // calculate a pitch based on the light sensor int pitch = map(reading, 0, 1023, minPitch, maxPitch); // play a tone CircuitPlayground.playTone(pitch, 100, false); Serial.println(pitch); }
Reference
While you’re working on the code, see the following for reference.
- See the guided tour again.
- Use the library reference as needed.
Cover photo from Adafruit on Flickr.