#include ; #include ; #include #include #include #define SPI_CS_ON digitalWrite(SPI_cs, LOW) // /cs = L #define SPI_CS_OFF digitalWrite(SPI_cs, HIGH) // /cs = H #define SPI_SD_ON digitalWrite(SPI_SD, LOW) // /cs = L #define SPI_SD_OFF digitalWrite(SPI_SD, HIGH) // /cs = H #define PIN 4 #define NUM_PIXELS 82 #define OPEN_COLLECTOR unsigned long time1; // measure time to scan LED strip const int SPI_cs = 9; // thermocouple chipselect const int SPI_SD = 10; // SD card chipselect byte spiDat[4]; //for temperature reading char strBuf[16]; //to character char c; char gpsBuf[45]; //for GPS readings int gpsflag = 0; int gpsnull = 0; TinyGPSPlus gps; SoftwareSerial ss(6,7); //software serial for GPS communication Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800); File myFile; const char *filename = "log.txt"; // file name // ------------------------- // initialization // ------------------------- void setup() { Serial.begin(9600); // initialization serial port ss.begin(9600); // softwearserial speed pinMode(SPI_cs, OUTPUT); // thermocouple pinMode(SPI_SD, OUTPUT); // SD card SPI_CS_OFF; SPI_SD_OFF; if (!SD.begin(SPI_SD)) { // sd card initialization Serial.println("initialization failed!"); //fail } else { Serial.println("initialization done."); // success Serial.println(filename); } SPI.begin(); SPI.setClockDivider(SPI_CLOCK_DIV4); // SPI clock divider SPI.setBitOrder(MSBFIRST); // most significant bit first strip.begin(); strip.show(); // Initialize all pixels to 'off' strip.setBrightness(200); } // ------------------------- // main loop // ------------------------- void loop() { word val3; val3 = getSpiData(1); getTemp(val3, strBuf); Serial.println(strBuf); delay(1); //strcat(gpsBuf,",TEMP="); //strcat(gpsBuf,strBuf); //Serial.println(gpsBuf); strcat(strBuf,","); writeSd(strBuf); gpsflag=0; while(gpsflag==0){ while(ss.available()>0){ // while GPS is working c = ss.read(); gps.encode(c); if(gps.location.isUpdated()){ sprintf(gpsBuf,"%d.%d.%d,%d.%d.%d,",gps.date.year(),gps.date.month(),gps.date.day(),gps.time.hour()+9,gps.time.minute(),gps.time.second()); gpsnull=0; while(gpsBuf[gpsnull]>0){ gpsnull = gpsnull+1; } dtostrf(gps.location.lat(), 3, 6, gpsBuf+gpsnull); // LAT = XXX.XXXXXX strcat(gpsBuf,","); dtostrf(gps.location.lng(), 3, 6, gpsBuf+gpsnull+10);//LONG = YYY.YYYYYY gpsSd(gpsBuf); Serial.print(gpsBuf); gpsflag=1; } }} //delay(1000); //time1 = millis(); // Serial.println(time1); knightRider(1, 10, 4, 0xFF1000); // Cycles, Speed, Width, RGB Color (original orange-red) //Serial.println(millis()-time1); //delay(1000); } // // logging in sd card(temperature) // byte writeSd(char *str) { SPI.setDataMode(SPI_MODE0); // changing SPI mode SPI.setClockDivider(SPI_CLOCK_DIV4); myFile = SD.open(filename, FILE_WRITE); if(myFile) { myFile.print(str); // write one line in SD card myFile.close(); } else { return false; } return true; } byte gpsSd(char *str) { SPI.setDataMode(SPI_MODE0); // changing the SPI mode SPI.setClockDivider(SPI_CLOCK_DIV4); myFile = SD.open(filename, FILE_WRITE); if(myFile) { myFile.println(str); // write one line in SD card myFile.close(); } else { return false; } return true; } // // temperature data from SPI // word getSpiData(byte num) { byte i; SPI.setDataMode(SPI_MODE1); // changing the SPI mode SPI.setClockDivider(SPI_CLOCK_DIV64); SPI_CS_ON; for(i = 0; i < 2; i++) { // get only 2 byte #ifdef OPEN_COLLECTOR spiDat[i] = ~SPI.transfer(0); // send dummy data #else spiDat[i] = SPI.transfer(0); // send dummy data #endif } SPI_CS_OFF; return ((word)spiDat[0] << 8) | (word)spiDat[1]; } // // temperature reading to character // void getTemp(word spival16, char *str) { word val, vali; byte sign, vals; val = spival16 >> 2; if(val & 0x2000) { // checking a bit of the sign // negative (two's complement) val = ~val + 1; // to positive val &= 0x3FFF; // extract the reading sign = true; // making a negative } else { // positive sign = false; } // devide integer and decimal vali = val >> 2; // integer(upper 11 bits) vals = (byte)val & 0x03; // decimal(lower 2 bits) vals = vals * 25; // 25=0.25*100 decimal to integer // display the number if(sign) { sprintf(str, "-%d.%-2d", vali, vals); // negative } else { sprintf(str, "%d.%-2d", vali, vals); // integer } } //Theatre-style crawling lights with rainbow effect void theaterChaseRainbow(uint8_t wait) { for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q=0; q < 3; q++) { for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on } strip.show(); delay(wait); for (uint16_t i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } } } // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } void rainbow(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { for(i=0; i0; x--) { old_val[x-1] = dimColor(old_val[x-1], width); strip.setPixelColor(x-1, old_val[x-1]); } strip.show(); delay(speed); } for (int count = NUM_PIXELS-1; count>=0; count--) { strip.setPixelColor(count, color); old_val[count] = color; for(int x = count; x<=NUM_PIXELS ;x++) { old_val[x-1] = dimColor(old_val[x-1], width); strip.setPixelColor(x+1, old_val[x+1]); } strip.show(); delay(speed); } } } void clearStrip() { for( int i = 0; i