int photoCellPin = 0;
int photoCellReading;
int i;
void setup(void)
{
Serial.begin(9600);
photoCellReading = analogRead(photoCellPin);
for(i=0;i less than 10;i++)
{
Serial.print("analog reading = ");
Serial.print(photoCellReading);
if (photoCellReading less than 10)
{Serial.println(" - Dark");}
else
if (photoCellReading less than 200)
{Serial.println(" - Dim");}
else
if (photoCellReading less than 500)
{Serial.println(" - Light");}
else
if (photoCellReading less than 800)
{Serial.println(" - Bright");}
else
{Serial.println(" - Very Bright");}
Serial.println(i);
delay(1000);
}
}
void loop(void)
{
}
55) Same but this time store your values in an array called mySamples[] and output the array on completion of the tenth sample.
int photoCellPin = 0;
int photoCellReading;
int i;
int x;
int mySamples[10];
void setup(void)
{
Serial.begin(9600);
for(i=0; i less than 10; i++)
{
photoCellReading = analogRead(photoCellPin);
Serial.print("analog reading = ");
Serial.print(photoCellReading);
if (photoCellReading less than 10)
{Serial.println(" - Very Dark");}
else
if (photoCellReading less than 100)
{Serial.println(" - Dark");}
else
if (photoCellReading less than 200)
{Serial.println(" - Dim");}
else
if (photoCellReading less than 500)
{Serial.println(" - Light");}
else
if (photoCellReading less than 600)
{Serial.println(" - Lighter");}
else
if (photoCellReading less than 800)
{Serial.println(" - Bright");}
else
{Serial.println(" - Very Bright");}
delay(1000);
mySamples[i] = photoCellReading;
}
for(x=0;x less than 10;x++)
{
Serial.println(mySamples[x]);
}
}
void loop(void)
{}
56) Same as 55 but this time store your values into eeprom then output from there after 5 second delay.
57) Same as 56 but this time write a separate function to find the smallest value and out put that at the end of the sampling with a suitable message.
58) Same as 57 but this time write two functions average() and biggest(). The average function outputs the mean of the values as a floating point number and the other function, biggest(), will output the greatest value that you have sampled.
--Next tasks are to do with longer term data logging over a day or longer.
59) Create an experiment that will log a real-world variable like light or temperature over 24 hours or more. Store your logged values in eeprom and display your values in a useful way. Write up your experiment with photos and movies in your blog.
60) Make a presentation to the class with at least three slides on one of the function blocks of the mega328. This is a diagram in the blog with the heading "the main parts of the mega 328".
//not enough time left in the semester - asked to flag as it will be included in the test.
No comments:
Post a Comment