6,15 → 6,18 |
** MOSI/CMD - PB3 |
** MISO/DAT0 - PB4 |
** CLK - PB5 |
** CS/CD/DAT3 - PB2 (10) |
** CS/CD/DAT3 - PD4 (4) |
|
I2C pins PC4, PC5 |
|
*/ |
|
#include <Wire.h> |
#include <Wire.h> |
#include <math.h> |
#include <SD.h> |
#include <stdlib.h> |
#include <SD.h> |
|
#define chipSelect 10 |
#define chipSelect 4 |
|
|
#define address 0x44 // A0 = L |
32,8 → 35,7 |
void setup() |
{ |
Wire.begin(); // join i2c bus (address optional for master) |
// I2C pins PD4, PD5 |
// |
|
pinMode(3, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
pinMode(5, OUTPUT); // LED pro blikani, aby bylo videt, ze to neco dela |
Serial.begin(9600); // Zmerena intenzita osvetleni se bude vypisovat na seriovou linku |
140,11 → 142,29 |
return (1000.0/pow(2.0,16)*ret); |
} |
|
char *ftoa(char *a, double f, int precision) |
{ |
long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000}; |
|
char *ret = a; |
long heiltal = (long)f; |
itoa(heiltal, a, 10); |
while (*a != '\0') a++; |
*a++ = '.'; |
long desimal = abs((long)((f - heiltal) * p[precision])); |
itoa(desimal, a, 10); |
return ret; |
} |
|
void loop() |
{ |
float luxVIS=0; |
float luxIR=0; |
|
char dataString[40]; |
char luxVISch[10]; |
char luxIRch[10]; |
|
set_light_sensor(SENSE_VIS); //setup sensor for visible measuring |
led_blink(); // Delay for measurement |
luxVIS=get_light_measurement(); |
153,13 → 173,10 |
led_blink(); // Delay for measurement |
luxIR=get_light_measurement(); |
|
ftoa(luxVISch,luxVIS,2); |
ftoa(luxIRch,luxIR,2); |
// make a string for assembling the data to log: |
String dataString = "$LOG"; |
dataString += String((int)count); // print number of measurement |
dataString += ","; |
dataString += String((int)luxVIS, DEC); // print number of measurement |
dataString += ","; |
dataString += String((int)luxIR, DEC); // print number of measurement |
sprintf(dataString,"$LUX01 %d %s %s",count, luxVISch, luxIRch); |
|
// open the file. note that only one file can be open at a time, |
// so you have to close this one before opening another. |
170,6 → 187,9 |
dataFile.println(dataString); |
dataFile.close(); |
// print to the serial port too: |
Serial.print(luxVIS,3); |
Serial.print(" "); |
Serial.println(luxIR,3); |
Serial.println(dataString); |
count++; |
} |