Imagine | Develop | Create
#include <LiquidCrystal.h> #include <SPI.h> #include <SD.h> #define upPIN 0 #define startstopPIN 1 #define downPIN 18 #define InPinA 17 #define InPinB 16 #define InSePinA 13 #define InSePinB 12 #define InSePinC 11 #define OutPinA 14 #define OutPinB 15 #define OutSePinA A5 #define OutSePinB A6 #define OutSePinC A7 #define chipSelect 10 unsigned int data[16]; unsigned long delaytime = 1; unsigned long timeslogged = 0; unsigned long currenttime = 0; File dataFile; LiquidCrystal lcd(2, 3, 4,5, 6, 7); void setup() { lcd.begin(16, 2); pinMode(startstopPIN, INPUT); pinMode(downPIN, INPUT); pinMode(upPIN, INPUT); pinMode(InSePinA, OUTPUT); pinMode(InSePinB, OUTPUT); pinMode(InSePinC, OUTPUT); while(!SD.begin(chipSelect)) { lcd.autoscroll(); lcd.setCursor(0,0); lcd.print(" SD Card failed "); lcd.setCursor(0,1); lcd.print("Press start to try again"); while(digitalRead(startstopPIN)==LOW){} while(digitalRead(startstopPIN)==HIGH){} } dataFile = SD.open("datalog.csv", FILE_WRITE); while(!dataFile) { lcd.setCursor(0,0); lcd.print(" SD Card failed "); lcd.setCursor(0,1); lcd.print("Error opening file for logging"); } lcd.clear(); lcd.noAutoscroll(); lcd.print("Log every:"); lcd.print(delaytime); lcd.print("S"); lcd.setCursor(0,1); /* while(digitalRead(startstopPIN)==LOW) { while(digitalRead(upPIN)==HIGH) { delaytime++; if(delaytime>=99999) { delaytime = 99999; } } while(digitalRead(downPIN)==HIGH) { delaytime--; if(delaytime<=0) { delaytime = 0; } } } */ dataFile.println("num,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16"); dataFile.flush(); lcd.clear(); lcd.print("Starting in:3"); delay(1000); lcd.setCursor(12,0); lcd.print("2"); delay(1000); lcd.setCursor(12,0); lcd.print("1"); delay(1000); lcd.clear(); lcd.print("Times Logged:"); currenttime = millis(); } void loop() { for(int i=0;i<8;i++) { selectLED(i); data[i] = analogRead(InPinA); data[i+8] = analogRead(InPinB); } dataFile.print(timeslogged); for(int i=0;i<16;i++) { dataFile.print(","); dataFile.print(data[i]); } dataFile.println(); dataFile.flush(); timeslogged++; lcd.setCursor(0,1); lcd.print(timeslogged); while(currenttime+1000>millis()){} currenttime = millis(); } void selectLED(byte A) { switch (A) { case 0: digitalWrite(InSePinA, LOW); digitalWrite(InSePinB, LOW); digitalWrite(InSePinC, LOW); break; case 1: digitalWrite(InSePinA, HIGH); digitalWrite(InSePinB, LOW); digitalWrite(InSePinC, LOW); break; case 2: digitalWrite(InSePinA, LOW); digitalWrite(InSePinB, HIGH); digitalWrite(InSePinC, LOW); break; case 3: digitalWrite(InSePinA, HIGH); digitalWrite(InSePinB, HIGH); digitalWrite(InSePinC, LOW); break; case 4: digitalWrite(InSePinA, LOW); digitalWrite(InSePinB, LOW); digitalWrite(InSePinC, HIGH); break; case 5: digitalWrite(InSePinA, HIGH); digitalWrite(InSePinB, LOW); digitalWrite(InSePinC, HIGH); break; case 6: digitalWrite(InSePinA, LOW); digitalWrite(InSePinB, HIGH); digitalWrite(InSePinC, HIGH); break; case 7: digitalWrite(InSePinA, HIGH); digitalWrite(InSePinB, HIGH); digitalWrite(InSePinC, HIGH); break; case 8: digitalWrite(InSePinA, LOW); digitalWrite(InSePinB, LOW); digitalWrite(InSePinC, LOW); break; break; } }