Smaller screens (1100px<) might have website design issues.
Challenge 1: Attach and Test Phototransistor
What is the highest result you can get? What is the lowest?
The highest value we got was around 680 and the lowest was 450. We would barely get a value around 800 but due to the inconsistency of this, we would set any light values greater than 680 to 800.
Experiment with the different resistors. Which gives us the best sensitivity in the classroom with the lights on? What about with the lights off?
The brown-black-orange resistor (10k Ohms) was the most sensitive and responsive, whether the light was on or off, and was why we chose to use it for our instrument.
Challenge 2: Halt Under a Bright Light
Sorry Mr. Green, I believe our group did not write code for challenge two, for we were spending a lot of time on our instrument.
In your own words, explain the difference between analog and digital. Ensure you address the specific ranges of values.
Analog pins are able to return integers from 0 to 1023. The main function of analog pins are to read analog sensors, like the phototransistors we used.
Digital pins on the other hand, whether set as INPUT, INPUT_PULLUP, or OUTPUT return/set to HIGH or LOW. Only two states, 0 or 1, which makes it useful for coding with items such as LEDs or buttons.
Challenge 3: Mapping
I believe my group did code this but I am not adding it to my website for I did not help in anyway.
What is mapping?
In the Arduino Docs, the map method is described as "[r]e-maps a number from one range to another." That is, a value in the range of the first two bounds gets mapped to the range of the last two parameters. The math for the mapping follows (note that the method uses integer math):
long map(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
For the Servo code, I would assume the light amount would be mapped from 0 to 200, and then the mapped value would be used in the .writeMicroseconds as so:
.writeMicroseconds(1500+mappedLightAmount, 1500-mappedLightAmount);
In the Theremin-teresting challenge, the light amount which is contrained from 480-680 (which could have been done using the .constrain() method instead of the if statement we used), was mapped to an integer from 0-11. The mapped value was used to select an note from an array of 12 elements.
Challenge 4: Theremin-teresting 💗
For the challenge the parts used were a phototransistor, a piezo speaker, two buttons, and an LCD screen. The buttons determine what octave the user wants to play their notes in, the red decreasing the octave, the green increasing it (C0-C8). The phototransistor was used to determine what note in the specified octave would play (C-B). The LCD screen (shoutout Aiman) was used to display the current note, octave, and an error message that can pop up if the user attempts to go below or beyond the valid octaves. The piezo button was used to play the notes.
The code is very much straightforward and simple but I learned a lot along the way and had a few hurdles to overcome.
In the setup, we see the code setting up the LCD screen and the custom speaker-character which is used, and explains the use of the 'Speaker', 'minimum', 'middle', and 'maximum' arrays. In the setup method the variables are initialized and the pins for the button and the speaker are set.
In the loop method, the first block of code deals with button bouncing, and updating the user's current octave through the 'updateScalePosition' method - which checks whether the octave can change without going out of bounds. The next block of code is for reading the light amount, and setting any exception-values (above 680 or below 480) to 680 or 480. The light amount is then mapped to what note is to be played, or rather, what index is to play in an array of notes. As can be seen in the tone method, the parameter for the frequency is a note frequency at index of the mapped light amount. At the end is the code for the LCD screen.
Below is the code for the challenge and the video, where I attempt to play "Mary Had a Little Lamb".