EasyManua.ls Logo

SunFounder 3in1 Kit - Page 194

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder 3in1 Kit
using millis() for timing with an interval of 5000ms.
previousMillis = millis();
...
while (millis() - previousMillis <= interval) {
...
}
During these five seconds, wave a hand around the photoresistor, the maximum and minimum
values of the detected light are recorded and assigned to lightHigh and lightLow respectively.
sensorValue = analogRead(photocellPin);
if (sensorValue > lightHigh) {
lightHigh = sensorValue;
}
if (sensorValue < lightLow) {
lightLow = sensorValue;
}
3. Now you can start playing this Thermin. Read the value of the photoresistor to sensorValue and map it from
the small range to the large range to be used as the frequency of the buzzer.
void loop()
{
/* play*/
sensorValue = analogRead(photocellPin); //read the value of A0
pitch = map(sensorValue, lightLow, lightHigh, 50, 6000); // map to the
˓buzzer frequency
if (pitch > 50) {
tone(buzzerPin, pitch, 20);
}
delay(10);
}
4.5.15 5.15 EEPROM
EEPROM is a memory, so the data it stores will not be erased when the main control board is turned off. You can use
it to record some data and read it the next time you turn it on.
As an example, you can make a sports counter that keeps track of how many rope skippings you do every day.
You can also write data to it in one program and read it in another. For example, when you are working on a car project,
the speeds of the two motors are inconsistent. You can write a calibration program to record the compensation value
of the motor speed.
Required Components
In this project, we need the following components.
Its definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
3 in 1 Starter Kit 380+
190 Chapter 4. Basic Projects

Related product manuals