#include SoftwareSerial Serial_photo(3,4); // tx, rx const int numReadings = 10; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average int sensorPin = 1; // analog input pin to hook the sensor to //int sensorValue = 0; // variable to store the value coming from the sensor void setup() { Serial_photo.begin(9600); // initialize serial communications // initialize all the readings to 0: for (int thisReading = 0; thisReading < numReadings; thisReading++) readings[thisReading] = 0; } void loop() { // subtract the last reading: total = total - readings[readIndex]; // read from the sensor: readings[readIndex] = analogRead(sensorPin); // add the reading to the total: total = total + readings[readIndex]; // advance to the next position in the array: readIndex = readIndex + 1; // if we're at the end of the array... if (readIndex >= numReadings) // ...wrap around to the beginning: readIndex = 0; // calculate the average: average = total / numReadings; //average = map(average, 0, 1024, 1024, 0); // send it to the computer as ASCII digits //Serial_photo.println(average); delay(1000); // delay in between reads for stability //sensorValue = analogRead(sensorPin); // read the value from the sensor //sensorValue = map(sensorValue, 0, 1024, 1024, 0); //Serial_photo.println(sensorValue); // print value "x" to Serial Monitor Serial_photo.write(average); //delay(500); // short delay so we can actually see the numbers }