Commit dbae2a86 authored by Indiana Brown's avatar Indiana Brown

Test

parent a1276a5d
//Libraries
#include "ThingSpeak.h"
#include <WiFi.h>
#include <SPI.h>
//Program variables
int sInput1;
int sInput2;
int sInput3;
int vccPin = 13;
//Averages variables
int Avg1, Avg2, Avg3, Avg4;
......@@ -40,7 +39,12 @@ void setup() {
String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") {
Serial.println("Update the firmware of the WiFi shield to avoid unexpected issues.");
}
}
//Sets the pin mode for pin 13 to output and gives it a 5v current
pinMode(vccPin, OUTPUT);
digitalWrite(vccPin, HIGH);
//Establishes ThingSpeak client
ThingSpeak.begin(client);
}
......@@ -49,10 +53,11 @@ void loop() {
connectToWPA();
Serial.println("Reading data.");
takeReadings();
//debug(); //For showing the program working (speeds up reading time and prints to console, otherwise remains the same).
dailyReading = ((Avg1 + Avg2 + Avg3 + Avg4)/4);
//Print for debug
Serial.print("Daily reading is: ");
Serial.print(dailyReading);
Serial.println(dailyReading);
Serial.println("Attempting to send data.");
//Attempt to write the data to ThingSpeak
ThingSpeak.setField(3, dailyReading);
......@@ -88,37 +93,45 @@ void connectToWPA() {
//Takes four averages (once every six hours) for the purpose of reporting the daily reading.
void takeReadings(){
//First average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0);
sInput2 = analogRead(A1);
sInput3 = analogRead(A2);
Avg1 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
//Delay 6 hours
delay(21600000);
//Second average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0);
sInput2 = analogRead(A1);
sInput3 = analogRead(A2);
Avg2 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
//Delay 6 hours
delay(21600000);
//Third average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0);
sInput2 = analogRead(A1);
sInput3 = analogRead(A2);
Avg3 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
//Delay 6 hours
delay(21600000);
//Fourth average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0);
sInput2 = analogRead(A1);
sInput3 = analogRead(A2);
Avg4 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
//Delay 6 hours
delay(21600000);
......@@ -127,10 +140,12 @@ void takeReadings(){
//Debug method to demonstrate that my program works.
void debug(){
//First average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0);
sInput2 = analogRead(A1);
sInput3 = analogRead(A2);
Avg1 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
Serial.print("First average: ");
Serial.println(Avg1);
//Delay 10 seconds
......@@ -138,10 +153,12 @@ void debug(){
//Second average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0);
sInput2 = analogRead(A1);
sInput3 = analogRead(A2);
Avg2 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
Serial.print("Second average: ");
Serial.println(Avg2);
//Delay 10 seconds
......@@ -149,10 +166,12 @@ void debug(){
//Third average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0);
sInput2 = analogRead(A1);
sInput3 = analogRead(A2);
Avg3 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
Serial.print("Third average: ");
Serial.println(Avg3);
//Delay 10 seconds
......@@ -160,10 +179,12 @@ void debug(){
//Fourth average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0);
sInput2 = analogRead(A1);
sInput3 = analogRead(A2);
Avg4 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
Serial.print("Fourth average: ");
Serial.println(Avg4);
//Delay 10 seconds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment