【Follow me Season 2 Episode 1】Summary submission post: All task videos and code downloads
[Copy link]
First of all, I am honored to participate in the first episode of the second season of follow me. In addition to study and work, I have the energy and time to get in touch with the Adafruit Circuit Playground Express development board. Now I will share with you the development process.
All video demonstration videos:
Full version
Material display:
In this event, I purchased two materials: Circuit Playground Express motherboard and rotor.
Purchase physical picture display:
Mission results display
Getting Started Task: 01 Ardunio ide environment setup + material display + onboard LED lighting
Corresponding post address: https://bbs.eeworld.com.cn/thread-1293111-1-1.html
Software environment construction:
This time I used the compilation software for Arduino to realize the function.
Official download website: https://www.arduino.cc/en/software
The software is a one-click installation process:
After the installation is complete, open the IDE, and install Arduino SAMD in the Boards Manager on the left column. Connect the development board and you can see the correct board model displayed above.
Task: Light up the onboard LED
Simply use Arduino to flash the onboard LED light. Looking at the official schematic, we can see that D13 is connected to pin 13.
Software flow chart:
The software operation code is as follows:
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, 1);
delay(1000);
digitalWrite(13, 0);
delay(1000);
}
Software renderings after compilation:
Test actual picture:
You can change the LED flashing interval by modifying the time in the delay function
Basic Task 1 (Must Do): Control the onboard colorful LED, light up the marquee and change the color
Corresponding post link: https://bbs.eeworld.com.cn/thread-1293113-1-1.html
This task is relatively simple and can be achieved using the Adafruit_NeoPixel.h library. Seven different colors are set to cycle through.
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#define PIN 8
#define NNUMPIN 10
Adafruit_NeoPixel pixels(NNUMPIN, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// write your initialization code here
pixels.begin();
}
void loop() {
// write your code here
static uint8_t led_num = 0;
//static uint32_t colors[8] = {0x040304, 0x000505, 0x050005, 0x050500, 0x050005, 0x000A00, 0x0A0000,0x0A000A};
static uint32_t colors[7] = {0x0A0000, 0x000A00, 0x00000A, 0x050500, 0x050005, 0x000505, 0x040304};
//static uint32_t colors[8] = {0x011011, 0x22022, 0x033033, 0x44044, 0x055055, 0x66066, 0x77777,0x088088};
static uint8_t color_num = 0;
static Adafruit_NeoPixel pixels(NNUMPIN, PIN, NEO_GRB + NEO_KHZ800);
pixels.clear();
pixels.setPixelColor(led_num, colors[color_num]);
pixels.show();
led_num++;
if (led_num == NNUMPIN) {
led_num = 0;
color_num++;
if (color_num == 8)
color_num = 0;
}
delay(200);
}
Basic Task 2 (Required): Monitor ambient temperature and light, and display comfort level through onboard LEDs
Corresponding post link: https://bbs.eeworld.com.cn/thread-1293113-1-1.html
By referring to the officially released schematic diagram and the code of the CircuitPython library, we can derive the relationship between the pin voltage (A8) and temperature and light (A9).
The software flowchart is as follows:
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include "SensorAB.h"
#define PIN 8
#define NUMPIXELS 10
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// write your initialization code here
Serial.begin(115200);
pixels.begin();
}
void loop() {
// write your code here
const double temperature = get_temperature(A9);
const double photocell = get_photocell(A8);
pixels.clear();
if (temperature < 14) {
pixels.setPixelColor(5, 0, 0, 10);
} else if (temperature < 18 && temperature >= 14) {
pixels.setPixelColor(6, 0, 5, 5);
} else if (temperature >= 18 && temperature <= 20) {
pixels.setPixelColor(7, 0, 10, 0);
} else if (temperature > 20 && temperature <= 25) {
pixels.setPixelColor(8, 5, 5, 0);
} else if (temperature > 25) {
pixels.setPixelColor(9, 10, 0, 0);
}
if (photocell > 1000) {
pixels.setPixelColor(0, 10, 0, 0);
} else if (photocell > 500 && photocell <= 1000) {
pixels.setPixelColor(1, 5, 5, 0);
} else if (photocell >= 200 && photocell <= 500) {
pixels.setPixelColor(2, 0, 10, 0);
} else if (photocell >= 50 && photocell < 200) {
pixels.setPixelColor(3, 0, 5, 5);
} else if (photocell < 50) {
pixels.setPixelColor(4, 0, 0, 10);
}
pixels.show();
Serial.print("temperature:" + String(temperature) + " sheshidu " + "photocell:" + String(photocell) + " lux\n");
delay(1000);
}
Effect diagram after software simulation:
The actual pictures are as follows:
Basic Task 3 (Required): Proximity Detection - Set a safe distance and display it through the onboard LED. When an intrusion is detected, an audible alarm is triggered.
Corresponding post link: https://bbs.eeworld.com.cn/thread-1293113-1-1.html
Using an infrared sensor, the IR LED emits pulses of a certain frequency, and the analog value measured by the receiver is read. When the analog value increases, an object is approaching.
Test phenomenon: When there is no object approaching, all the light beads are off or only one is displayed. As the object approaches, more and more light beads will light up.
The software code is as follows:
#include <Adafruit_CircuitPlayground.h>
#define SAFE_DISTANCE 500 // 定义安全距离
const int alertTone = 500; // 警报音调
const int irTransmitterPin = 25; //引脚定义
const int irReceiverPin = A10;
void setup()
{
CircuitPlayground.begin();
Serial.begin(9600); //
pinMode(irReceiverPin, INPUT); // 红外传感器输入
pinMode(irTransmitterPin, OUTPUT);// 红外led输出
delay(100);
}
void loop() {
sendIRPulse();
int distance = analogRead(irReceiverPin); // 读取红外传感器的值
displayDistance(distance);
checkForIntrusion(distance);
delay(300);
}
void displayDistance(int distance) {
int ledCount = map(distance, 290, SAFE_DISTANCE, 1, 10); // 将距离值映射到0-10的LED数量
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(", LED Count: ");
Serial.println(ledCount);
for (int i = 0; i < 10; i++) {
if (i < ledCount) {
CircuitPlayground.setPixelColor(i, 0, 255, 0);
} else {
CircuitPlayground.setPixelColor(i, 0);
}
}
}
void checkForIntrusion(int distance) {
if (distance > SAFE_DISTANCE) {
Serial.println("Intrusion detected!");
playAlertTone();
}
}
void sendIRPulse() {
for (int i = 0; i < 32; i++) {
digitalWrite(irTransmitterPin, HIGH);
delayMicroseconds(13);
digitalWrite(irTransmitterPin, LOW);
delayMicroseconds(13);
}
}
void playAlertTone() {
CircuitPlayground.playTone(alertTone, 500); // 播放警报音500ms
}
Advanced Task (Must Do): Make a tumbler - Show different lighting effects during the tumbler's movement
Corresponding post link: https://bbs.eeworld.com.cn/thread-1293114-1-1.html
This task is essentially to use the onboard gyroscope to detect the attitude of the board and then give the corresponding lighting effect. What I achieved is to light up the corresponding light according to the tilt direction of the board.
Software flow chart:
The code is as follows:
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include "Acc.h"
#define PIN 8
#define NUMPIXELS 10
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// write your initialization code here
Serial.begin(115200);
pixels.begin();
if (!init_acceleration()) {
Serial.println("ERROR");
}
}
void loop() {
// write your code here
std::array<double, 2> data = get_acceleration();
double length = sqrt(pow(data[0], 2) + pow(data[1], 2));
int degree = atan(-1 * data[0] / data[1]) / M_PI * 180;
degree += data[0] * data[1] >= 0 ? 180 : 0;
pixels.clear();
if (degree >= 15 && degree <= 165) {
pixels.setPixelColor((degree-15)/30+(data[0]<0?5:0), length*10, abs(10-length*10), 0);
}
pixels.show();
Serial.println("X:" + String(data[0]));
Serial.println("Y:" + String(data[1]));
Serial.println("degree" + String(degree));
Serial.println();
delay(100);
}
Project summary:
I would like to make a brief summary of this activity. In this activity, I used the Arduino IDE compiler software to have a simple understanding of the resources on the Adafruit Circuit Playground board. After learning the activity tasks, I realized the understanding of different functional modules, searched for information, and conducted in-depth learning on the development board in various ways. I wrote the code myself and realized the power of the development board.
As for hardware, you can make some DIY products by yourself and develop circuit boards based on existing resources. This will bring some fun to your life while you are working and studying.
Finally, I would like to thank EEworld and Digi-Key Electronics for organizing this event. I hope I will have the opportunity to participate in more learning in the future.
The code is as follows:
|