Complete code re-write plus new feature (frequency control)#3
Open
csatt wants to merge 6 commits intocubic-print:masterfrom
Open
Complete code re-write plus new feature (frequency control)#3csatt wants to merge 6 commits intocubic-print:masterfrom
csatt wants to merge 6 commits intocubic-print:masterfrom
Conversation
This a complete re-write of the sketch with the following changes:
- More comments to help reader understand how it works
- More use of named constants for readability
- More use of functions for readability
- Better constant and variable names
- Unnecessary code removed
- On-board LED heartbeat is now always on, but code rewritten to
not interfere with timing
- Implementation of Paul Hutchison's improvements:
- Glowing LED for pushbutton (OPTIONAL)
- Frame starts in standby mode
- Removed LED only mode
- Additional analog input to control electromagnet duty
(OPTIONAL)
- Adjustments to ranges
- NEW FEATURE: frequency control
Note that this sketch is compatible with with both the original hardware
design and with either or both of the hardware modifications added by
Paul Hutchison (pushbutton LED and electromagnet strength knob.)
However, the constants HW_HAS_PUSHBUTTON_LED and
HW_HAS_MAG_STRENGTH_KNOB must be set appropriately below.
The frequency control feature uses the same knob (potentiometer) as the
LED brightness. The ability to vary the frequency allows the user to
find the resonant frequency of the object(s). Frequency control mode is
entered by "double clicking" the pushbutton when it is in the standby
mode. The LED brightness value is captured on entry to the frequency
control mode, and the knob is temporarily re-purposed to control the
frequency. The speed control knob and the electromagnet strength knob
work as normal while in frequency control mode. Frequency control mode
is exited and normal slow motion mode is entered when the pushbutton is
pressed. At this transition, the frequency value is captured and
continues to be used while the frame is powered on. Additionally, the
value is written to EEPROM. This value is read the next time the frame
is powered on and is used until the user enters frequency control mode
again to change it.
In frequency control mode, the pushbutton LED blinks rapidly. On
hardware that does not implement the pushbutton LED, the only way to
tell that it is in frequency control mode is to go ahead and turn the
knob that normally controls the brightness and see if it instead is
controlling the frequency.
Restored the mode that Paul Hutchison had removed in which the magnet is turned off and only the LED strip is on. However, there is a constant INCLUDE_MAGNET_OFF_MODE that may be set to "false" to skip this mode. Also renumbered the modes to be in their more logical order. This is purely cosmetic; the current code doesn't even require the numerical values to be consecutive.
The PUSHBUTTON_LED_STANDBY_PERIOD_MS constant is change from 2000 to 3000 to slow the "throbbing" down even more (personal preference). The BASE_FREQ_HZ and FREQ_RANGE_HZ are changed to 77.0 and 14.0 respectively. This gives a frequency range from 70 Hz to 84 Hz, tunable in the new frequency control mode.
Fixed one comment and one blank line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request is to add a version 4.0 of the Arduino sketch. This is a new file, so if this pull request is accepted, the previous code will remain available and unchanged.
The new feature is the ability to adjust the base frequency using the same knob that is used for LED brightness control. The code was also re-written from scratch in the hope that it will be easier to understand for anyone wanting to make their own modifications or to leverage it for another project.
Please see the header comment for the TimeFrame_V4_0_full.ino file for details.