iocontrol_serialout
- behavior:
- minimal program
- start handler immediately, and print out a message at regular interval showing current time in ms
- pre-requisite:
- none
- concepts:
- IO_Control
- begin
- execute
- enableScheduler
- isSchedulerTimeEvent(_status)
- use "DeclareHandlerBegin" and "DeclareHandlerEnd" for declare a handler function
- enable scheduler with handler function for repeated execution
- handler cannot start at t=0 (usually t=86 due to setup and other overhead)
- IO_Control
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-iocontrol_serialout
iocontrol_serialout_fsm1
- behavior:
- modified from iocontrol_serialout
- implement a FSM (finite state machine) to control sequential printing of messages
- pre-requisite:
- iocontrol_serialout
- concepts:
- add a variable for state, count from 0 to 2 and goes back to 0 again
- use switch statement
- effect of "interval" on duration for each state
- prepare for complex case of finite state machine
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-iocontrol_serialout_fsm1
iocontrol_serialout_fsm2
- behavior:
- repeat the print sequence in iocontrol_serialout_fsm1 for a number of times
- pre-requisite:
- iocontrol_serialout_fsm1
- concepts:
- extended from iocontrol_serialout
- add another variable to control repeat count
iocontrol_serialin
- behavior:
- read in characters from Serial monitor and display in the handler
- pre-requisite:
- iocontrol_serialout
- concepts:
- Serial
- available
- readStringUntil
- String and its functions
- if ... else ...
- boolean expression
- Serial
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-iocontrol_serialin
binout_timedwrite
- behavior:
- turn on GPIO 12 at 1000ms and turn off at 2000ms
- pre-requisite:
- iocontrol_serialout
- concepts:
- BinOutControl
- init
- enableScheduler
- read
- write
- PinMgr
- request
- basic steps to allocate resource for a pin
- handler for BinOutControl
- write HIGH after onTimeMS, and LOW after offTimeMS
- BinOutControl
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-binout_timedwrite
binout_serialin_timedwrite
- behavior:
- parse input from Serial Monitor to control when to turn on LED at GPIO12 and duration
- two formats:
- <duration>
- <relative start time>,<duration>
- with checking of input message from Serial Monitor
- reject if comma at start, or more than one comma
- <duration> = 1000 may not have any observable change due to turn around time of serial communication being too long
- pre-requisite:
- binout_timedwrite
- iocontrol_serialin
- concepts:
- String
- indexOf
- substring
- toInt
- String
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-binout_timedwrite
binout_play_oneseq
- behavior:
- playback a sequence on IO12 using GPIO output, at t=2000ms after reset, for 2 times
- pre-requisite:
- binout_timedwrite
- concepts:
- BinOutControl
- playRelTime
- isXXX(_status) - relating to sequence
- BinOutSequence
- addSetState( duration, state)
- BinOutControl
- extension
- play sequence for one time and two times to illustrate difference between "OneSeqEnded" and "AllSeqEnded"
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-binout_play_oneseq
binout_play_altseq
- behavior:
- playback two sequences alternatively on IO12, using GPIO output
- pre-requisite:
- binout_play_oneseq
- iocontrol_serialout_fsm1
- iocontrol_serialout_fsm2
- concepts:
- BinOutControl.playRelTime in handler
- use finite state machine concept
- use "isAllSeqEnded()"
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-binout_play_altseq
binout_serialin_playseq_immed
- behavior:
- play sequence immediately according to input from Serial monitor
- two inputs:
- 0 - start playing sequence 0 immediately
- 1 - start playing sequence 1 immediately
- pre-requisite:
- binout_play_oneseq
- binout_play_altseq
- concepts
- BinOutControl.playRelTime invoke in handler
- String::equals
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-binout_serialin_playseq_immed
binout_serialin_playseq_follow
- behavior:
- play sequence AFTER current sequence finished playback, according to input from Serial monitor
- modified from binout_serialin_playseq_immed
- pre-requisite:
- binout_serialin_playseq_immed
- concepts:
- BinOutControl.isPlaying
- BinOutControl.isAllSeqEnded
- add "nextSeqIndex" to remember which sequence to play next
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-binout_serialin_playseq_follow
binin_changetime
- behavior:
- detect change of BOOT button (IO09) and report time of change and state AFTER change
- pre-requisite
- iocontrol_serialout
- concepts:
- BinInControl
- init - pin and input mode
- enableScheduler
- enableInterrupt - RISING, FALLING, CHANGE, HIGH, LOW
- isBinInTriggered
- getInterruptTime
- getInterruptState
- BinInControl
- Refer to https://www.designandmake.org/pages/viewpage.action?pageId=232799560#Lecture3:ComputingSystemsandProgramming-binIn_changetime
adc_read
- circuit:
- Use 2-axis joystick as in https://lastminuteengineers.com/joystick-interfacing-arduino-processing/
- Connections
2-axis joystick ESP32C3 VRx IO00 VRy IO01 GND GND +5V 3.3V
- behavior:
- joystick analog outputs connect to IO00 and IO01 respectively
- read analog outputs every 100ms and outputs on Serial Monitor
- pre-requisite:
- iocontrol_serialout
- concepts
- ADCControl
- init - adc_index (must be 1), pin index (must be 0 to 4)
- read
- getMaxValue
- ADCControl
adc_thres
- circuit:
- use 2-axis joystick as in https://lastminuteengineers.com/joystick-interfacing-arduino-processing/
- connections
2-axis joystick ESP32C3 VRx IO00 VRy IO01 GND GND +5V 3.3V
- behavior:
- set threshold for three regions, and report an ID for region (0,1, or 2) of each analog input on Serial Monitor when ID changed
- pre-requisite:
- adc_read
- concepts
- ADCControl
- enableScheduler and handler
- setThreshold
- isIndexChanged
- getLastIndex
- getLastChangeTime
- getLastValue
- getLastXXX only valid when isIndexChanged is true
- vector and initialization
- std::vector - search for "std::vector" online for documentation
- template
- push_back
- ADCControl
adc_binin_joystick
- circuit:
- use 2-axis joystick as in https://lastminuteengineers.com/joystick-interfacing-arduino-processing/
- connections
2-axis joystick ESP32C3 VRx IO00 VRy IO01 GND GND +5V 3.3V SW IO05
- behavior:
- handlers for detecting ADC at IO00 and IO01, and threshold in three ranges
- when button is pushed or released, change time is determined and current state of ADC0 and ADC1 are printed
- pre-requisite:
- adc_thres
- binin_changetime
- concepts:
- INPUT_PULLUP for IO05, so that no external pull-up resistor is required
pwm_setduty
- behavior:
- use PWM output on IO12 to change brightness from fully-off to fully-on
- interval = 50ms, each interval increment duty by 100
- pre-requisite:
- iocontrol_serialout
- concepts:
- PWMControl
- init
- getFreq
- setDuty(duty)
- maximum 6 PWM channels, map to any GPIO output
- all with same frequency, but can have different duty
- PWMControl
pwm_play_oneseq
- behavior:
- play back a PWM sequence for two times
- pre-requisite:
pwm_setduty
- binout_play_oneseq
- concepts:
- PWMSequence
- addSetDuty
- addFade
- PWMControl
- playRelTime
- PWMSequence
servo_setAngle
- circuit:
- use SG90 servo motor
- connections:
SG90 ESP32C3 PWM IO08 VCC 5V GND GND
- behavior:
- set servo motor (at IO08) position using handler in IO_Control
- angle from 20 to 160 degrees; angle increment by 5 degree every 500ms, to allow enough time for the servo motor to move to the angle
- pre-requisite:
- iocontrol_serialout
- concepts
- ServoControl
- init
- setAngle
- on-time of control signal for servo motor
- ServoControl
- note:
- DO NOT USE THE FULL RANGE OF ANGLE, AND LEAVE SOME MARGIN (e.g. 20 degrees in this example), OTHERWISE MAY DAMAGE THE SERVO MOTOR
servo_play_oneseq
- circuit:
- use SG90 servo motor
- connections:
SG90 ESP32C3 PWM IO08 VCC 5V GND GND
- behavior:
- play back one servo motor sequence for once
- smooth movement when interval is smaller (50ms vs 20ms)
- pre-requisite:
servo_setAngle
- binout_play_oneseq
- concepts:
- ServoSequence
- addSetAngle
- addMoveFromToAngle
- has to pass ServoControl object for checking
- maximum angular speed = 60deg/0.1s
- angle limits = from 0 to 180 degrees
- angle should NOT be too close to the extreme limit; prefer to use the range 20 to 160 instead to avoid damaging servo motor
- ServoSequence
tone_setTone
- circuit:
- use piezo speaker
- connections:
piezo speaker ESP32C3 +ve IO13 GND GND
- behavior:
- play a frequency and a note, each for 250ms
- pre-requisite
- iocontrol_serialout_fsm1
- iocontrol_serialout_fsm2
- concepts
- ToneControl
- init
- setTone
- setNote ( notebase, octave, duty)
- NoteBaseType refer to ToneControl.h
- octave - from 0 to 8
- getMaxDuty
- setTone
- freq ==0 means silent
- ToneControl
tone_play_oneseq
- circuit:
- use piezo speaker
- connections:
piezo speaker ESP32C3 +ve IO13 GND GND
- behavior:
- play a tone sequence for once
- pre-requisite
- tone_setTone
- binout_play_oneseq
- concepts:
- ToneSequence
- addSetTone
- addSetNote
- addInterpolateTone
- ToneSequence
mpr121_touchrelease_event
- circuit:
- use MPR121 breakout board as in https://learn.sparkfun.com/tutorials/mpr121-hookup-guide/all
- connections:
MPR121 ESP32C3 3.3V 3.3V IRQ IO07 SCL IO10 SDA IO06 ADD GND GND
- behavior:
- initialize MPR121 module and report touch and release event at each terminal and time of detection
- pre-requisite
- binin_changetime
- concepts
- MPR121Control
- isTouchReleaseEvent
- touchedTimeMS[]
- releasedTimeMS[]
- for loop
- access of element in vector/array (not std::vector)
- MPR121Control
addrled_setColor
- circuit:
- WS2812 strip with at least 4 LEDs
- connections
WS2812 ESP32C3 DIN IO19 +5V 5V GND GND
- behavior:
- set color of 4 LEDs in NeoPixel in three groups
- use FSM with 4 states to set color for each group, and change colors
- pre-requisite:
- iocontrol_serialout_fsm1
- iocontrol_serialout_fsm2
- concepts
- AddrLEDControl
- init
- setRGB
- setHSV
- setHSV
- https://www.lifewire.com/what-is-hsv-in-design-1078068
- hue - 0 to 360
- saturation - 0 to 100
- value - 0 to 100
- https://www.lifewire.com/what-is-hsv-in-design-1078068
- setHSV_noMap
- https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use#hsv-hue-saturation-value-colors-dot-dot-dot-3024464
- hue - 0 to 65535
- saturation - 0 to 255
- value - 0 to 255
- https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use#hsv-hue-saturation-value-colors-dot-dot-dot-3024464
- std::vector
- array
- clear
- push_back
- AddrLEDControl
addrled_play_seqs
- circuit:
- WS2812 strip with at least 4 LEDs
- connections
WS2812 ESP32C3 DIN IO19 +5V 5V GND GND
- behavior:
- defined three sequences
- expect 4 LEDs, and divided into three groups, each group play one sequence
- for one group, sequence is continued playing after ending the sequence
- pre-requisite:
- binout_play_altseq
- binout_play_altseq
- concepts:
- AddrLEDControl
- playRelTime
- AddrLEDSequence
- addSetRGB
- addSetHSV
- addSetInterpolateRGB
- addSetInterpolateHSV
- AddrLEDControl
addrLED_seq_pause_resume
- circuit:
- WS2812 strip with at least 2 LEDs
- connections
WS2812 ESP32C3 DIN IO19 +5V 5V GND GND
- behavior:
- define two sequences and play back each sequence to each group, with one LED per group
- one sequence paused after playing 2nd command, and then resume after the other sequence completed playing
- pre-requisite:
- addrled_play_seqs
- concepts:
- AddrLEDControl::pauseBeforeNextCommand()
- AddrLEDControl::isOneSeqPaused()
- AddrLEDControl::resume()
oled_display_time
- circuit:
- use SH1106 or SSD1306 OLED display
- connections
SH1106 or SSD1306 display ESP32C3 VCC 3.3v GND GND SCL IO10 SDA IO06
- behavior:
- initialize SH1106 display and display current time in HH:MM:SS format
- time since reset
- pre-requisite:
- binout_timedwrite
- concepts:
- define SSD1306 or SH1106 to enable use of corresponding OLED display
- conditional compilation, with #ifdef ... #else ... #end
- https://learn.adafruit.com/adafruit-gfx-graphics-library
- use "Time by Michael Margolis", in https://github.com/PaulStoffregen/Time/tree/master
- define "getTime()" to get current time
- use handler of SH1106Control to update time every 1 second
oled_display_ntptime
- circuit:
- use SH1106 or SSD1306 OLED display
- connections
SH1106 or SSD1306 display ESP32C3 VCC 3.3v GND GND SCL IO10 SDA IO06
- behavior:
- connect to the SSID with password in the source code, and connect to the NTP server
- initialize SH1106 display and display current time in HH:MM:SS format
- If failed to connect to SSID, time since reset will be used instead of the local time
- pre-requisite:
- oled_display_time
- concepts:
- connect to SSID using WiFiControl
oled_display_bitmap
- circuit:
- use SH1106 or SSD1306 OLED display
- connections
SH1106 or SSD1306 display ESP32C3 VCC 3.3v GND GND SCL IO10 SDA IO06
- behavior:
- initialize SH1106 display and display three bitmaps in sequence, one normal and one with color flipped
- 1 state (at statewith screen blank
- pre-requisite:
- oled_display_time
- concepts
- prepare bitmap for arduino
- https://learn.adafruit.com/adafruit-gfx-graphics-library?view=all
- drawBitMap
- bitmaps
- display.oled_command for turning on or off display
mp3_dfplayer
- circuit:
- use the DFPlayer Mini MP3 Player as in https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299
- need a micro-SD card for the player
- need a speaker of less than 3W
- connection
DFPlayer Mini MP3 Player ESP32 C3 speaker VCC 5V RX IO01 TX IO00 GND GND SPK_1 speaker + SPK_2 speaker -
- video: