Browse Source

stationdata.

master
Your Name 5 years ago
parent
commit
f1a024ff0c
1 changed files with 79 additions and 5 deletions
  1. +79
    -5
      batterycharge_stationdata/arduino/batterycharge_stationdata/batterycharge_stationdata.ino

+ 79
- 5
batterycharge_stationdata/arduino/batterycharge_stationdata/batterycharge_stationdata.ino View File

@ -6,10 +6,43 @@
*/
int ADC_VAL0 = A0;
//NOTE: we are using 1.1V VRef, so keep ADC input low.
//current
int ADC_VAL0 = A1;
//
int ADC_VAL1 = A4;
//smoothing
const int numReadings = 100;
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 readings2[numReadings]; // the readings from the analog input
int readIndex2 = 0; // the index of the current reading
double total2 = 0; // the running total
int average2 = 0; // the average
int start = 0;
int ADCVAL0_State = 0;
int ADCVAL1_State = 0;
int writeresult = 0;
// the setup routine runs once when you press reset:
void setup() {
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
readings2[thisReading] = 0;
}
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the ADC_VAL0's pin an input:
@ -54,12 +87,53 @@ void setup() {
// the loop routine runs over and over again forever:
void loop() {
// subtract the last reading:
total = total - readings[readIndex];
total2 = total2 - readings2[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(ADC_VAL0);
readings2[readIndex] = analogRead(ADC_VAL1);
// add the reading to the total:
total = total + readings[readIndex];
total2 = total2 + readings2[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;
start = 1;
writeresult = 1;
}
// calculate the average:
average = total / numReadings;
average2 = total2 / numReadings;
// send it to the computer as ASCII digits
if(start){
ADCVAL0_State = average;
ADCVAL1_State = average2;
}
// read the input pin:
int ADCVAL0_State = analogRead(ADC_VAL0);
//int ADCVAL0_State = analogRead(ADC_VAL0);
if (writeresult){
//int ADCVAL1_State = analogRead(ADC_VAL1);
// print out the state of the button:
Serial.println(ADCVAL0_State);
delay(10000); // delay in between reads for stability
Serial.print(" ADCVAL0 Current in mA, ");
Serial.print(ADCVAL0_State);
Serial.print(",");
Serial.print(" ADCVAL1 Battery Voltage divby 10, ");
Serial.println(ADCVAL1_State);
delay(5000); // delay in between reads for stability
writeresult = 0;
}
//Trying to debug why I cant change a bit in a register. fucking wiring. fuck search engines.
//int dog = ADMUX;

Loading…
Cancel
Save