//Program by Jeremy Blum
//www.jeremyblum.com
//SD Card Demonstration
//Some code from public domain work by Tom Igoe
//Assisted by Inigo D. Villanueva III
//Edited by Ignacio D. Villanueva III
//For thesis purpose entitled "
//Thesis members: James Santiago. Belen Cruz. Franzes Francisco, Kaye Agut
#include <SD.h> //SD Card Library
//SPI SD Card Pins
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
int CS_pin = 10;
int pow_pin = 8;
// this constant won't change:
const int buttonPinA = 2; // the pin that the pushbutton is attached to
const int buttonPinB = 5;
// Variables will change:
int buttonBeeCounterA = 0; // counter for the number of button presses
int beeCounterA = 0; // current state of the button
int lastBeeCounterA = 0; // previous state of the button
int buttonBeeCounterB = 0; // counter for the number of button presses
int beeCounterB = 0; // current state of the button
int lastBeeCounterB = 0; // previous state of the button
long lastEvent= 0; // The last time a bee has entered the feeding station
long interval= 300; // The debounce time
void setup() {
Serial.begin(9600);
Serial.println("Initializing Card");
//CS Pin is an output
pinMode(CS_pin, OUTPUT);
//SD Card will Draw Power from Pin 8, so set it high
pinMode(pow_pin, OUTPUT);
digitalWrite(pow_pin, HIGH);
//Initialize Card
if (!SD.begin(CS_pin))
{
Serial.println("Card Failure");
return;
}
Serial.println("Card Ready");
// initialize the button pin as a input:
pinMode(buttonPinA, INPUT);
pinMode(buttonPinB, INPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
beeCounterA = digitalRead(buttonPinA);
// compare the buttonState to its previous state
if (beeCounterA != lastBeeCounterA)
{
// if the state has changed, increment the counter
if (beeCounterA == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
{
lastEvent= millis(); // a bee can be recorded)
// if the current state is HIGH then the button
// wend from off to on:
buttonBeeCounterA++;
Serial.println("Bees are being detected entering Feeding Station A");
Serial.print("number of bees that entered Feeding Station A: ");
Serial.println(buttonBeeCounterA);
}
lastBeeCounterA= beeCounterA;
}
beeCounterB = digitalRead(buttonPinB);
if (beeCounterB != lastBeeCounterB)
{
// if the state has changed, increment the counter
if (beeCounterB == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
{
lastEvent= millis(); // a bee can be recorded)
// if the current state is HIGH then the button
// wend from off to on:
}
buttonBeeCounterB++;
Serial.println("Bees are being detected entering Feeding Station B");
Serial.print("number of bees that entered Feeding Station B: ");
Serial.println(buttonBeeCounterB);
}
lastBeeCounterB= beeCounterB;
//Write Log File Header
File logFile = SD.open("DATALOG.csv", FILE_WRITE);
if (logFile)
{
logFile.print(buttonBeeCounterA);
logFile.print(",");
logFile.println(buttonBeeCounterB);
Serial.print(buttonBeeCounterA);
Serial.print(",");
Serial.println(buttonBeeCounterB);
}
else
{
logFile.print("LogFile cannot be opened");
}
}
i wonder why there is no data being stored in my SD card, i have deleted the string and state it this way..
![]()