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 "MCP3221.h" | |
const byte DEV_ADDR = 0x4D; // I2C address of the MCP3221 (Change if needed) | |
MCP3221 mcp3221(DEV_ADDR); // constructs a new MCP3221 object with the relevant I2C address | |
void setup() { | |
Serial.begin(9600); // initiallizes the Serial Communications Port (at 9600bd) | |
Wire.begin(); // initiallizes the I2C Communications bus | |
while(!Serial); // waits for Serial Port to initialize |
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
/* | |
HOOK-UP: NORMALLY OFF | |
--------------------- | |
Connect one pin of the push-button or toggle switch to pin D5. | |
Connect a 10K pull-down resistor between the above pin and GND. | |
Connect the other pin of the push-button or toggle switch to 5V. | |
HOOK-UP: NORMALLY ON | |
-------------------- | |
Connect one pin of the push-button or toggle switch to pin D5. |
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
typedef struct Scr_t { | |
union { | |
u16 data; | |
struct { | |
u16 tile : 10; | |
u16 hflip : 1; | |
u16 vflip : 1; | |
u16 pal : 4; | |
}; | |
}; |
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
struct hours_byte { | |
unsigned int format: 1; // range: 0-1, 0=24h 1=12h | |
unsigned int ampm: 1; // range: 0-1, 0=AM 1=PM | |
unsigned int tenshours: 2; // range: 0-2 | |
unsigned int hours: 4; // range: 0-15 (guessing it never goes over 9) | |
}; | |
void pHour(hours_byte when) { | |
Serial.print(when.tenshours, DEC); | |
Serial.print(when.hours, DEC); |
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 i = 42; | |
int *p = &i; | |
// '*' means 'points to' and '&' means 'address of' ('p' is a pointer to the address of integer 'i') |
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
// Reference: http://stackoverflow.com/questions/16683146/can-macros-be-overloaded-by-number-of-arguments | |
#ifdef bitSet | |
#undef bitSet | |
#endif | |
#ifdef bitClear | |
#undef bitClear | |
#endif |
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
/* | |
GPIOR | |
----- | |
Three general purpose I/O registers that can be used for storing any information (GPIOR0, GPIOR1 and GPIOR2) | |
These registers are particularly useful for storing global variables and status flags, since they are accessible | |
to bit-specific instructions such as SBI, CBI, SBIC, SBIS, SBRC, and SBRS. | |
Note that only GPIOR0 is bit-addressable | |
References: |
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
// DDRD (R/W) pin direction (0 = INPUT / 1 = OUTPUT) | |
// PORTD (R/W) pin state (INPUT: 0 = LOW / 1 = HIGH | OUTPUT: 0 = PULL-UP DIACTIVATED / 1 = PULL-UP ACTIVATED) | |
// PIND (R) pin state (INPUT ONLY: 0 = LOW / 1 = HIGH) | |
// bit(n) // calculates value of n-th bit (returns: 0 / 1) | |
// bitRead(byteName, n) // gets value of n-th bit of byte (returns: 0 / 1) | |
// bitSet(byteName, n) // sets value of n-th bit of byte to 1 | |
// bitClear(byteName, n) // sets value of n-th bit of byte to 0 | |
// bitWrite(byteName, n, val) // sets value of n-th bit of byte to 0 or 1 |
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
// Source & much additional info: | |
// http://playground.arduino.cc/Code/BitMath | |
y = (x >> n) & 1; // n=0..7. stores nth bit of x in y. y becomes 0 or 1. | |
x &= ~(1 << n); // forces nth bit of x to be 0. all other bits left alone. | |
x &= (1<<(n+1))-1; // leaves alone the lowest n bits of x; all higher bits set to 0. | |
x |= (1 << n); // forces nth bit of x to be 1. all other bits left alone. | |
x ^= (1 << n); // toggles nth bit of x. all other bits left alone. | |
x = ~x; // toggles ALL the bits in x. |
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
extras/* linguist-documentation |
NewerOlder