170 views|0 replies

8

Posts

1

Resources
The OP
 

【Follow me Season 2 Episode 1】Task submission: rush and slow version [Copy link]

 

One month went by too fast. Well, maybe it was because I was too green, not good enough, and too slow to understand. Fortunately, I was able to submit the task in time for the end. Thanks to EEworld and Digi-Key for their great support and providing such a good activity for us to learn. Next is the summary of my own tasks.

Summarized video link: https://training.eeworld.com.cn/video/40822

Software code link: https://download.eeworld.com.cn/detail/%E5%B0%8F%E7%A5%9E123/634247

Let me introduce myself first. I am Xiaoshen, an amateur electronics enthusiast. I saw the [Follow me Season 2, Issue 1] event in my spare time, so I participated. I didn't expect that I would be lucky enough to get the opportunity for my first participation. The Adafruit Circuit Playground Express development board used in this event has a variety of sensors on board, such as light sensors, infrared sensors, microphones, accelerometers, as well as buttons, LED lights, speakers, etc. The board is small in size, which is convenient for doing some electronic DIY. The actual picture is as follows:

I purchased three items for this mission, including the Adafruit Circuit Playground Express development board (required), the ultrasonic sensor (optional, to complete the distance detection), and the servo (optional, to complete the Squidward mission). Below is a family photo.

Next is the task summary:

[Beginner's task (must be done): set up the development environment and light up the onboard LED]

【Required materials】Adafruit Circuit Playground Express development board, MicroUSB cable, computer

Use the onboard buttons to light up different LED lights. My software logic here is that when the A button is clicked, LED0 will light up red and last for 500ms before turning off; when the B button is clicked, LED1 will light up green and last for 500ms before turning off; when the A and B buttons are pressed at the same time, LED3 will light up yellow and last for 500ms before turning off.

input.buttonA.onEvent(ButtonEvent.Click, function () {
    light.setPixelColor(0, 0xff0000)
    pause(500)
    light.clear()
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
    light.setPixelColor(1, 0x00ff00)
    pause(500)
    light.clear()
})
input.buttonsAB.onEvent(ButtonEvent.Click, function () {
    light.setPixelColor(3, 0xffff00)
    pause(500)
    light.clear()
})

The video demonstration is as follows:

VID_20240825_204350_subtitle

[Basic Task 1 (Must Do): Control the onboard colorful LED, light up the marquee and change the color]

【Required materials】Adafruit Circuit Playground Express development board, MicroUSB cable, computer

The software logic is that when neither the A button nor the B button is pressed, all LED lights are green; when the A button is pressed, all LED lights turn red and last for 1 second, then a colorful marquee is displayed and lasts for 1 second, and then the green LED state is restored; when the B button is pressed, all LED lights turn blue and last for 1 second, then a multi-color marquee is displayed and lasts for 1 second, and then the green LED state is restored.

forever(function () {
    if (input.buttonA.isPressed()) {
        light.setAll(0xff0000)
        pause(1000)
        light.showAnimation(light.rainbowAnimation, 1000)
    } else {
        light.setAll(0x00ff00)
    }
    if (input.buttonB.wasPressed()) {
        light.setAll(0x0000ff)
        pause(1000)
        light.showAnimation(light.cometAnimation, 1000)
    } else {
        light.setAll(0x00ff00)
    }
})

The video demonstration is as follows:

VID_20240825_212509

[Basic Task 2 (Must Do): Monitor ambient temperature and light, and display comfort level through onboard LEDs]

[Required materials] Adafruit Circuit Playground Express development board, MicroUSB cable, computer, battery,

Use the onboard temperature sensor and light sensor to sense changes in the external ambient temperature and ambient light, and show the difference with the color of the LED and the number of LED lights. Here my software logic is to divide the temperature into three intervals, [-5~22][23~26][27~50]. When the temperature is [-5~22], the LED light displays blue, and as the temperature decreases, more LED lights are lit; when the temperature is [23~26], the LED light displays green, and as the temperature increases, more LED lights are lit; when the temperature is [27~50], the LED light displays red, and as the temperature increases, more LED lights are lit. The more suitable temperature is green, and the more the number, the more suitable it is. At the same time, the light is judged to be higher in brightness, and the more LEDs are lit, and 2~3 lights are more suitable. The display pictures are as follows:

In the refrigerator, the ambient temperature is low and the blue light is on. It may be that the door was open and the corresponding ambient temperature was not reached, so the green light will be on.

let value = input.lightLevel()
let value2 = input.temperature(TemperatureUnit.Celsius)
let list = [0, 1, 2, 3, 4]
let list2 = [5, 6, 7, 8, 9]
forever(function () {
    value = Math.min(input.lightLevel() / 51.2, 5)
    for (let i = 0; i <= value; i++) {
        light.setPixelColor(list[i], 0xffff00)
    }
    for (let k = value; k <= 10; k++) {
        light.setPixelColor(list[k], 0x000000)
    }
})
forever(function () {
    if (input.temperature(TemperatureUnit.Celsius) < 22) {
        value2 = Math.min(Math.abs(input.temperature(TemperatureUnit.Celsius) - 21) / 5.4, 5)
        for (let j = 0; j <= value2; j++) {
            light.setPixelColor(list2[j], 0x0000ff)
        }
        for (let l = value; l <= 10; l++) {
            light.setPixelColor(list[l], 0x000000)
    }
    } else {
        if (input.temperature(TemperatureUnit.Celsius) >= 22 && input.temperature(TemperatureUnit.Celsius) <= 26) {
            value2 = Math.min((input.temperature(TemperatureUnit.Celsius) - 21) / 1, 5)
            for (let m = 0; m <= value2; m++) {
                light.setPixelColor(list2[m], 0x00ff00)
            }
            for (let n = value; n <= 10; n++) {
            light.setPixelColor(list[n], 0x000000)
    }
        } else {
            value2 = Math.min((input.temperature(TemperatureUnit.Celsius) - 26) / 4.8, 5)
            for (let o = 0; o <= value2; o++) {
                light.setPixelColor(list2[o], 0xff0000)
            }
            for (let p = value; p <= 5; p++) {
            light.setPixelColor(list[p], 0x000000)
    }
        }
    }
})

The video demonstration is as follows:

202408310037

[Basic Task 3 (Must Do): Proximity Detection - Set a safe distance and display it through the onboard LED. When an intrusion is detected, an audible alarm is triggered]

【Required materials】Adafruit Circuit Playground Express development board, MicroUSB cable, computer, ultrasonic module

This task requires the use of the ultrasonic sensor purchased at the time to detect the distance of the object. At the same time, the collected data needs to be processed, and the corresponding number of LED lights will be lit according to the distance. The closer the distance, the less light, and the farther the distance, the more light. At the same time, the alarm threshold is set, and when it is close to 5cm, the buzzer will be triggered to sound as a warning.

let distance = 0
loops.forever(function () {
    pins.A2.digitalWrite(false)
    control.waitMicros(2)
    pins.A2.digitalWrite(true)
    control.waitMicros(10)
    pins.A2.digitalWrite(false)
    distance = pins.A1.pulseIn(PulseValue.High) / 58
    light.graph(distance, 30)
    if (distance < 5) {
        music.siren.play()
    } else {
        music.stopAllSounds()
    }
})

The video demonstration is as follows:

VID_20240830_003508

[Advanced Task (Must Do): Make a tumbler - Show different lighting effects during the movement of the tumbler]

[Required materials] Adafruit Circuit Playground Express development board, MicroUSB cable, computer, cat tumbler toy

Next, the task to be introduced is a must-do task. This is to steal the cat's toy. I guess it holds a grudge and wants to punch me. Attach a photo. Disassemble the cat tumbler toy, fix the development board on it, and modify it to light up the corresponding position LED light as the angle changes. It mainly uses the acceleration sensor to divide a circle into four quadrants to judge the values of x, y, and z to display the corresponding LED lights.

forever(function () {
    if (input.acceleration(Dimension.X) == 0 && input.acceleration(Dimension.Y) == 0 && input.acceleration(Dimension.Z) == 1023) {
        light.clear()
    } else {
        if (input.acceleration(Dimension.X) > 0) {
            if (input.acceleration(Dimension.Y) > 0) {
                if (input.acceleration(Dimension.X) > input.acceleration(Dimension.Y)) {
                    light.setPixelColor(7, 0xff0000)
                    control.waitMicros(100000)
                    light.clear()
                } else {
                    if (input.acceleration(Dimension.X) < input.acceleration(Dimension.Y)) {
                        light.setPixelColor(5, 0xff0000)
                        control.waitMicros(100000)
                        light.clear()
                    } else {
                        light.setPixelColor(6, 0xff0000)
                        control.waitMicros(100000)
                        light.clear()
                    }
                }
            } else {
                light.setPixelColor(9, 0xff0000)
                light.setPixelColor(8, 0xff0000)
                control.waitMicros(100000)
                light.clear()
            }
        } else {
            if (input.acceleration(Dimension.X) < 0) {
                if (input.acceleration(Dimension.Y) < 0) {
                    if (input.acceleration(Dimension.X) > input.acceleration(Dimension.Y)) {
                        light.setPixelColor(0, 0xff0000)
                        control.waitMicros(100000)
                        light.clear()
                    } else {
                        if (input.acceleration(Dimension.X) < input.acceleration(Dimension.Y)) {
                            light.setPixelColor(1, 0xff0000)
                            control.waitMicros(100000)
                            light.clear()
                        } else {
                            light.setPixelColor(3, 0xff0000)
                            control.waitMicros(100000)
                            light.clear()
                        }
                    }
                } else {
                    light.setPixelColor(2, 0xff0000)
                    control.waitMicros(100000)
                    light.clear()
                }
            } else {
                light.setPixelColor(4, 0xff0000)
                control.waitMicros(100000)
                light.clear()
            }
        }
    }
})

The video demonstration effect is as follows:

VID_20240831_161642

[ Creative Task 2: Squidward - Squidward's tentacles can expand or contract depending on the size of the surrounding sound]

[Required materials] Adafruit Circuit Playground Express development board, MicroUSB cable, computer, mineral water bottle, servo, silk thread, glue, tape, scissors, pen, paper and other tools

First prepare an empty mineral water bottle and cut it into two parts, one part for the octopus's body and legs, and the other part for the octopus's head;

Use a pen to draw the appearance of Squidward on light blue paper, and stick it on Squidward's head with tape. The specific effect after assembly is as follows:

The program logic follows the volume of the external sound. The number of LED lights that light up will change with the volume of the sound. At the same time, the speed of the servo will change with the volume. The angle of the servo is fixed and rotates between 45 and 135 degrees (because I tried to map the volume to the rotation angle of the servo before, the effect was not very good, so I changed the idea and reflected the volume on the rotation speed)

let VOL = 0
let speed = 0
let LEDcount = 0
let pos = 0
let list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
let numLED = 10
servos.A1.setRange(45, 135)
servos.A1.setAngle(45)
forever(function () {
    speed = Math.map(VOL, 0, 255, 0, 100)
    servos.A1.run(speed)
    servos.A1.setAngle(45)
    pause(40)
    servos.A1.setAngle(90)
    pause(40)
    servos.A1.setAngle(135)
    pause(40)
    servos.A1.setAngle(90)
    pause(40)
    pause(100)
})
forever(function () {
    let angle = 0
    VOL = input.soundLevel()
    LEDcount = Math.map(VOL, 60, 150, 0, 10)
    for (let i = 0; i <= LEDcount; i++) {
        light.setPixelColor(list[i], 0xff00ff)
        control.waitMicros(10000)
    }
    for (let j = LEDcount; j <= 10; j++) {
        light.setPixelColor(list[j], 0x000000)
    }
console.logValue("x", input.soundLevel())
    console.logValue("y", angle)
    console.logValue("z", VOL)
})

The demonstration effect is as follows:

VID_20240901_101032

[ Creative Task 3: Fruit Piano - Play music by touching the fruit and coordinate with the lighting effects]

[Required materials] Adafruit Circuit Playground Express development board, MicroUSB cable, computer, fruit, Dupont cable, etc.

This task requires the analog input function of the development board. Use the analog input of each pin and connect it to the fruit with a wire. Touch the fruits connected to different pins with your hands, and they will emit corresponding tones. When combined, they can play "beautiful" music, which is called fruit piano. Show my dried lemon to demonstrate the fruit piano.

forever(function () {
    if (input.touchA1.isPressed()) {
        music.playTone(988, music.beat(BeatFraction.Double))
        pause(1)
        music.stopAllSounds()
    }
    if (input.touchA2.wasPressed()) {
        music.playTone(880, music.beat(BeatFraction.Double))
        pause(1)
        music.stopAllSounds()
    }
    if (input.touchA3.wasPressed()) {
        music.playTone(784, music.beat(BeatFraction.Double))
        pause(1)
        music.stopAllSounds()
    }
    if (input.touchA4.wasPressed()) {
        music.playTone(698, music.beat(BeatFraction.Double))
        pause(1)
        music.stopAllSounds()
    }
    if (input.touchA5.wasPressed()) {
        music.playTone(659, music.beat(BeatFraction.Double))
        pause(1)
        music.stopAllSounds()
    }
    if (input.touchA6.wasPressed()) {
        music.playTone(587, music.beat(BeatFraction.Double))
        pause(1)
        music.stopAllSounds()
    }
    if (input.touchA7.wasPressed()) {
        music.playTone(523, music.beat(BeatFraction.Double))
        pause(1)
        music.stopAllSounds()
    }
})

The video demonstration effect is as follows:

VID_20240828_044043

Due to time constraints, I did not work on Creative 1. I hope to continue learning after the event.

[Learning experience] In fact, this task should not be difficult, but I am too new to it, and if I do it after work, the time is tight. Through this task, I learned how to light up LED lights, water lights, ultrasonic ranging, temperature, light, acceleration sensors, speakers, buttons and other applications. It basically covers the common electronic DIY fields. I hope I can have the opportunity to participate again in the future and continue to explore the electronic world.

The activity was great, we will continue next time!

Finally, I would like to thank EEworld, Digi-Key Electronics, and every partner who helped me again.

Attachment source code:

源代码.zip (743.64 KB, downloads: 1)
This post is from DigiKey Technology Zone
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list