Created
December 4, 2012 12:07
-
-
Save Gonzih/4203139 to your computer and use it in GitHub Desktop.
Arduino IR Read/Write
This file contains 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
#define DEBUG | |
#define ARR_SIZE 200 | |
int readPin = 11, debugPin = 13, writePin = 10; | |
// Debuging | |
#ifdef DEBUG | |
void debug() { | |
digitalWrite(debugPin, digitalRead(readPin)); | |
} | |
#endif | |
// Writing data to IR LED | |
unsigned long delays[] = { 103750, 452, 431, 459, 432, 1805, 431, 459, 439, 459, 439, 452, 432, 911, 8383, 452, 432, 459, 432, 1805, 438, 452, 432, 457, 439, 451, 439, 905 }; | |
void ir_write() { | |
boolean state = false; | |
int size = sizeof(delays) / sizeof(unsigned long); | |
for (int j = 0; j < size; j++) { | |
digitalWrite(writePin, state); | |
#ifdef DEBUG | |
digitalWrite(debugPin, state); | |
#endif | |
delayMicroseconds(delays[j]); | |
state = !state; | |
} | |
} | |
// Reading data from Photodiode | |
unsigned long arr[ARR_SIZE]; | |
unsigned long duration; | |
int i = 0; | |
void print_array() { | |
int size = sizeof(arr) / sizeof(unsigned long); | |
for (int i = 0; i < size; i++) { | |
Serial.print(arr[i]); | |
Serial.print(' '); | |
} | |
Serial.println(' '); | |
} | |
void ir_read() { | |
#ifdef DEBUG | |
debug(); | |
#endif | |
duration = pulseIn(readPin, HIGH); | |
arr[i] = duration; | |
i++; | |
duration = pulseIn(readPin, LOW); | |
arr[i] = duration; | |
i++; | |
if (i == ARR_SIZE) { | |
i = 0; | |
print_array(); | |
} | |
} | |
// Setup | |
void setup() { | |
pinMode(readPin, INPUT); | |
pinMode(debugPin, OUTPUT); | |
pinMode(writePin, OUTPUT); | |
Serial.begin(9600); | |
} | |
// Loop | |
void loop() { | |
ir_read(); | |
/*ir_write();*/ | |
} | |
/* | |
*/ |
This file contains 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
import '../rakefile.rb' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment