int photocellPin = 0;
int photocellReading;
void setup() {
Serial.begin(9600);
for (int i = 0; i <10; i++)
{
photocellReading = analogRead(photocellPin);
Serial.println(photocellReading);
delay(1000);
}
}
void loop()
{
}
Task 55:
int photocellPin = 0;
int photocellReading;
int mySamples[10];
void setup()
{
Serial.begin(9600);
for (int i = 0; i <10; i++)
{
photocellReading = analogRead(photocellPin);
mySamples[i] = photocellReading;
delay(1000);
}
}
void loop()
{
}
Task 56:
#include
int photocellPin = 0;
int photocellReading;
int EEPROMVal;
void setup() {
Serial.begin(9600);
for (int i = 1; i <=10; i++)
{
photocellReading = analogRead(photocellPin);
EEPROM.write(i, photocellReading);
delay(1000);
}
delay(5000);
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
Serial.println(EEPROMVal);
}
}
void loop()
{
}
Task 57:
#include
int photocellPin = 0;
int photocellReading;
int EEPROMVal;
void setup() {
Serial.begin(9600);
for (int i = 1; i <=10; i++)
{
photocellReading = analogRead(photocellPin);
EEPROM.write(i, photocellReading);
delay(1000);
}
delay(5000);
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
Serial.println(EEPROMVal);
}
smallest();
}
void smallest()
{
int smallestVal = 255;
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
if (EEPROMVal < smallestVal)
smallestVal = EEPROMVal;
}
Serial.println();
Serial.print(smallestVal);
Serial.println(" is the smallest value.");
}
void loop()
{
}
Task 58:
#include
int photocellPin = 0;
int photocellReading;
int EEPROMVal;
void setup() {
Serial.begin(9600);
for (int i = 1; i <=10; i++)
{
photocellReading = analogRead(photocellPin);
EEPROM.write(i, photocellReading);
delay(1000);
}
delay(5000);
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
Serial.println(EEPROMVal);
}
smallest();
biggest();
average();
}
void smallest()
{
int smallestVal = 255;
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
if (EEPROMVal < smallestVal)
smallestVal = EEPROMVal;
}
Serial.println();
Serial.print(smallestVal);
Serial.println(" is the smallest value.");
}
void biggest()
{
int biggestVal = 0;
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
if (EEPROMVal > biggestVal)
biggestVal = EEPROMVal;
}
Serial.println();
Serial.print(biggestVal);
Serial.println(" is the biggest value.");
}
void average()
{
float averageVal;
int totalVal = 0;
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
totalVal += EEPROMVal;
}
averageVal = totalVal / 10;
Serial.println();
Serial.print(averageVal);
Serial.println(" is the average.");
}
void loop()
{
}
Task 59:
Logging code:
#include
int photocellPin = 0;
int photocellReading;
void setup()
{
Serial.begin(9600);
for (int i = 1; i <=144; i++)
{
photocellReading = analogRead(photocellPin);
EEPROM.write(i, photocellReading);
Serial.println(photocellReading);
delay(600000);
}
}
void loop()
{
}
Recalling code:
#include
int EEPROMVal;
void setup()
{
Serial.begin(9600);
for (int i = 1; i <=144; i++)
{
EEPROMVal = EEPROM.read(i);
Serial.println(EEPROMVal);
}
}
void loop()
{
}
Data recorded in Bar Graph form:
No comments:
Post a Comment