оптоволокно для стеклоподъемников... до этого даже мерседесы еще не дошли
кан, вот ваша тема
Для начала не обязательно покупать дорогостоящие трансиверы можно поэксперементировать с тем что есть ниже опишу как из ИК диода и ИК передатчика сделать простой трансивер: Берем ИК диод Надеваем на него трубочку
Получаем Приемник оптическийберем оптовоконный кабель
отрезаем несколько жил собираем термоусадкой
ПОЛУЧАЕМ
КабелекБерем ИК диод или пульт для тестов
так же одеваем трубочку
Подключаем
Тестим
Все просто вот скетч для пробы писать отдельный не стал разместил тот что был
PHP код:/*
The circuit:
* LCD RS pin to digital pin 9
* LCD Enable pin to digital pin 7
* LCD R/W pin to digital pin 8
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* 10K resistor GND: to pin 3 LCD
* LCD 1 & 16 to ground
* LCD 2 & 15 +5V
* wiper to LCD VO pin (pin 3)
* ir_pin = 6
*/
#include <OneWire.h>
OneWire ds(10); // линия 1-Wire будет на pin 9
int ir_pin = 6; //Sensor pin 1 wired through a 220 ohm resistor
int ledPin = 12; //"Ready to Recieve" flag, not needed but nice
int debug = 0; //Serial connection must be started to debug
int start_bit = 2000; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)
#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 8, 7, 5, 4, 3, 2);
const int numRows = 4;
const int numCols = 20;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ir_pin, INPUT);
lcd.begin(numRows, numCols);
lcd.setCursor(0, 0);
lcd.print("Rem Demo v.2.0");
delay(3000);
lcd.setCursor(0, 0);
lcd.print(":-) ");
}
void loop() {
byte i;
byte present = 0;
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
ds.reset_search();
return;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
lcd.setCursor(0, 0);
lcd.print("Not Connect!");
return;
}
if ( addr[0] != 0x28) {
lcd.print("Device is not a DS18b20 family device.\n");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // запускаем конвертацию
delay(10); // скорее всего достаточно 750ms
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // считываем ОЗУ датчика
for ( i = 0; i < 9; i++) { // обрабатываем 9 байт
data[i] = ds.read();
}
// высчитываем температуру :)
int HighByte, LowByte, TReading, Tc_100;
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
Tc_100 = TReading/2;
lcd.setCursor(10, 1);
lcd.print("t.=");
lcd.print(Tc_100);
start:
int key = getIRKey(); //Fetch the key
/* lcd.setCursor(0, 1);
lcd.print("Key set:");
lcd.print(key);
lcd.print(" ");
*/
switch (key){
case 224:
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("Menu:");
delay(500);
goto menu;
break;
case 950:
lcd.setCursor(0, 1);
lcd.print("Tools");
digitalWrite(ledPin, HIGH);
break;
case 931:
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("IR Test");
digitalWrite(ledPin, LOW);
lcd.setCursor(0, 1);
lcd.print(" ");
break;
case 180:
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("left");
break;
case 179:
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("right");
break;
case 244:
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("up");
break;
case 245:
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("down");
break;
case 184:
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("HI");
break;
menu:
int key = getIRKey(); //Fetch the key
/* lcd.setCursor(0, 1);
lcd.print("Key set:");
lcd.print(key);
lcd.print(" ");
*/
if(key=950){
digitalWrite(ledPin, LOW);
delay(300);
goto start;}
else;
goto menu;
}
}
int getIRKey() {
int data[12];
//Ok, i'm ready to recieve
while(pulseIn(ir_pin, LOW) < 2200) { //Wait for a start bit
}
data[0] = pulseIn(ir_pin, LOW); //Start measuring bits, I only want low pulses
data[1] = pulseIn(ir_pin, LOW);
data[2] = pulseIn(ir_pin, LOW);
data[3] = pulseIn(ir_pin, LOW);
data[4] = pulseIn(ir_pin, LOW);
data[5] = pulseIn(ir_pin, LOW);
data[6] = pulseIn(ir_pin, LOW);
data[7] = pulseIn(ir_pin, LOW);
data[8] = pulseIn(ir_pin, LOW);
data[9] = pulseIn(ir_pin, LOW);
data[10] = pulseIn(ir_pin, LOW);
data[11] = pulseIn(ir_pin, LOW);
if(debug == 1) {
lcd.setCursor(0, 1);
lcd.println("-----");
}
for(int i=0;i<11;i++) { //Parse them
if (debug == 1) {
lcd.println(data[i]);
}
if(data[i] > bin_1) { //is it a 1?
data[i] = 1;
} else {
if(data[i] > bin_0) { //is it a 0?
data[i] = 0;
} else {
data[i] = 2; //Flag the data as invalid; I don't know what it is!
}
}
}
for(int i=0;i<11;i++) { //Pre-check data for errors
if(data[i] > 1) {
return -1; //Return -1 on invalid data
}
}
int result = 0;
int seed = 1;
for(int i=0;i<11;i++) { //Convert bits to integer
if(data[i] == 1) {
result += seed;
}
seed = seed * 2;
}
return result; //Return key number
}
Последний раз редактировалось xeonlink; 10.09.2010 в 11:25.
Эту тему просматривают: 1 (пользователей: 0 , гостей: 1)