0
Offline
Newbie
Karma: 0
Posts: 10
Arduino rocks
|
 |
« on: March 05, 2009, 01:30:08 pm » |
qui peut m'aidé a comprendre ce program c'est pour faire une telecomande LANC pour camescope sony
je je sait pas coment le modifier pour envoyer les comande au camescope
merci d'avance
#define rxPin 2 // Receive Status from LANC Device (unimplemented) #define txPin 3 // Send Commands to LANC DEVICE (works) #define ledPin 13 // LEB for activity status flickering #define bitMicroSeconds 104
byte ledPinState = 1;
void setup() { Serial.begin(57600); // 9600, 14400, 38400, 57600, 115200
// define pin modes for tx, rx, led pins: pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); pinMode(ledPin, OUTPUT);
// Blink LED 13 Just to Say 'Hello' digitalWrite(13,HIGH); delay(500); digitalWrite(13,LOW); delay(1000); digitalWrite(13,HIGH); delay(1000); digitalWrite(13,LOW); }
int block = 0; int state = 0; int in = 0;
void loop() {
int inBytes = Serial.available();
if (inBytes == 0) return;
if (inBytes >= 128) { Serial.print(0,BYTE); // Serial.flush(); return; } in = Serial.read();
if (in == 99) return;
/* switch (state) { case 0 : state = OkState(in); return; case 99: // ASCII 'c' for control */ SendCode(40,in); // 40 == 0x28 "Special command to videocamer" SendCode(40,in); toggleLed(); Serial.print(in,BYTE); /* state = 0; return; default: state = 0; return; } */ }
/* //READ //Serial.print("S: "); frameStartBitWait(); for(int byteNum = 0; byteNum < 8; byteNum++) { byte in = readByte(rxPin,104); lowWait(rxPin); Serial.print(in,DEC); if (byteNum!=7) Serial.print("."); else Serial.println(";"); } */
void SendCode(int type,int code) { frameStartBitWait(); writeByte(rxPin,type,bitMicroSeconds); // Video Cam Control lowWait(rxPin); writeByte(rxPin,code,bitMicroSeconds); // Tele/Wide }
void lowWait(int pin) { byte in = digitalRead(pin); while (in) { in = digitalRead(pin); } }
void frameStartBitWait() { // finds thge start of a telegram/frame unsigned long usec = pulseIn(rxPin,HIGH); while (usec < 5864) { // 6230 experimentally with a RTV900 usec = pulseIn(rxPin,HIGH); /* DEBUG Serial.print(usec); Serial.println(" microseconds"); */ }
/* DEBUG Serial.print("frame start after "); Serial.print(usec); Serial.println(" microseconds"); */ }
byte readByte(int pin,unsigned long uSec /* bit width*/ ) { byte result = 0; delayMicroseconds(uSec * 1.5); // skips the Start Bit and Land in the midlle of the first byte
for (int i = 0; i < 8; i++) { if (digitalRead(pin) == LOW) { // == *LOW* because bits inverted in LANC result++; } result <<= 1; delayMicroseconds(uSec); } delayMicroseconds(0.5*uSec); return result; // return happens at end of last (8ths) bit }
void writeByte(int pin, byte value, unsigned uSec /* bit width */) { delayMicroseconds(uSec); // wait for stop bit pinMode(pin,OUTPUT); for (int i = 0; i < 8; i++) { boolean bit = value & 0x1; digitalWrite(pin,!bit); // NOT (!) pin because all data is inverted in LANC value >>= 1; delayMicroseconds(uSec); } pinMode(pin,INPUT); // return happends at end of last (8th) bit }
void toggleLed() { // set the LED pin using the pinState variable: digitalWrite(ledPin, ledPinState); // if pinState = 0, set it to 1, and vice versa: ledPinState = !ledPinState; }
|