Overview
Let’s make a fortune cat whose eyes can light up and it can wave its hand to you when you approach to it.
Suitable kit: mCookie302
Module List
Module
Other Equipment
- USB cable*1
- Sensor cable*4
- Sensor shell
- Building blocks or other fixation structures
Module Setup
Setup
- Assemble modules and sensors together:
- Stick the red core module, battery base and the green hub together;
- Connect the servo connector to pin 6/7 of Hub;
- Connect the servo to pin 1 (the lower three pins) of servo connector;
- Connect the Line Finder to pin A0 of Hub;
- Connect the two ColorLEDs to pin 8/9 of Hub;
- Plug one end of USB cable into the battery base, and connect the other end co computer;
Programming
Required Program Blocks
Program Thought
Detect the distance from the Line Finder of pin A0, if it is less than 800 (there is someone approaching), use every time program to change the brightness of ColorLEDs and the angle of the servo, implementing actions of waving hand and blinking eyes.
Start to Program
1. Detect the distance of line finder A0
ColorLed prepare: connect two ColorLEDs to pin 8
Send the value of A0 line finder to the serial monitor.
Wait for the value of A0 Line Finder to be less than 800 (someone is approaching).
2. Wave hand and blink eyes.
Execute the internal program 30 times (the starting point of count is 60, and the ending point is 90).
。
Set the blue brightness level of the two ColorLEDs to (i-60)×4 (blue brightness level is 0-120)
。
Set the angle of the servo to the repeated time I (60-90 degrees).
。
Execute the internal program 30 times (the starting point of count is 90 and the ending point is 60).
。
Set the blue brightness level of the two ColorLEDs to (i-60)×4 (the blue brightness level is 120-0).
。
Set the angle of the servo to the repeated time I (90-60 degrees).
。
Test the result
After uploading, when you approach to the Line Finder near pin A0, the ColorLEDs will flash once, and the servo will spins once.
Q: When you touch the nose of the fortune cat, it can only wave hand once, how to modify the program to make it wave hand several times?
A: You can use “every time” program block, have you some ideas?
Execute “waving hand” and “blinking eyes” code twice.
Technical Specification
Relative Cases
FAQ
|