This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The ledIO() function turns on or off an LED (in a particular color - if RGB) based on the mode passed to it. The mode can be the color of LED - in lower case - if RGB | |
//or simply on or off if a single color LED | |
void ledIO(uint8_t mode) | |
{ | |
switch (mode) { | |
case 1: //RED | |
digitalWrite(RLED, HIGH); | |
digitalWrite(GLED, LOW); | |
digitalWrite(BLED, LOW); | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SD.h> | |
File file; | |
const uint8_t CS = 10; // SD chip select | |
// YOUR SKETCH SHOULD UPDATE THESE SIX VALUES | |
// EACH TIME BEFORE CREATING YOUR SD CARD FILE | |
unsigned int year = 2015; | |
byte month = 6; | |
byte day = 18; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Datatypes | |
1. void --> Returns no information | |
2. boolean --> 8 bit (0 or 1) | |
3. char --> signed 8-bit (-128 to 127) | |
4. Unsigned char/byte --> unsigned 8-bit (0 to 255) | |
5. int/short --> signed 16-bit (-32,768 to 32,767) | |
Due --> signed 32-bit (-2,147,483,648 to 2,147,483,647) | |
6. unsigned int/word --> unsigned 16-bit (0 to 65,535) | |
Due --> unsigned 32-bit (0 to 4,294,967,295) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int calcNoOfDays(int Month, int Year) | |
{ | |
int noOfDays[] = | |
{ 0, 31, 0, 31, 30, 31, 30, 31, | |
31, 30, 31, 30, 31 | |
}; | |
if (Month == 2) { | |
if (Year % 4 == 0 || Year % 400 == 0) | |
noOfDays[2] = 29; | |
else if (Year % 4 != 0 || Year % 100 == 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <TinyGPS++.h> // For gps | |
#include <SoftwareSerial.h> // For communicating with the gps | |
struct dateTime { // Stores date and time for DateTime calculations | |
int Year; | |
int Month; | |
int Date; | |
}; | |
dateTime current; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This custom version of delay() ensures that the gps object | |
// is being "fed". | |
static void smartDelay(unsigned long ms) | |
{ | |
unsigned long start = millis(); | |
do | |
{ | |
while (ss.available()) | |
gps.encode(ss.read()); | |
} while (millis() - start < ms); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <util/delay.h> | |
#include <avr/interrupt.h> | |
void setLED(uint8_t LED); | |
uint8_t currentLED; | |
uint8_t times = 0; | |
/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
knownUnits = new Dictionary<string, long> | |
{ | |
{ "", 1L }, // no unit is same as unit B(yte) | |
{ "B", 1L }, | |
{ "KB", 1024L }, | |
{ "MB", 1024L * 1024L}, | |
{ "GB", 1024L * 1024L * 1024L}, | |
{ "TB", 1024L * 1024L * 1024L * 1024L} | |
// fill rest as needed | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This function returns the amount of RAM currently in available | |
uint8_t * heapptr, * stackptr; | |
void check_mem() { | |
stackptr = (uint8_t *)malloc(4); // use stackptr temporarily | |
heapptr = stackptr; // save value of heap pointer | |
free(stackptr); // free up the memory again (sets stackptr to 0) | |
stackptr = (uint8_t *)(SP); // save value of stack pointer | |
Serial.print(F("Heap: ")); | |
Serial.println(*heapptr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int sampleData(int analogPin, int samples = 8, int sampleInterval = 50) { | |
int sampleData[samples]; | |
int val = 0; | |
for (int i = 0; i<samples; i++) { | |
sampleData[i] = analogRead(analogPin); | |
val = val + sampleData[i]; | |
delay(sampleInterval); | |
} | |
val = (val / samples); | |
return map(val, 550, 1023, 100, 0); |
OlderNewer