7017| 5
|
[项目] 一个现实版的电报(也可看做指路仪) |
我的编线非常简陋,谅之谅之 这个(东西)可以通过摇杆来控制灯亮,这也是我看了一个电影(忘了名字),特务拿着灯传递信息,但是我感觉十分麻烦。 so make this 程序之路十分坎坷....... (抽支烟) 嗯,这样简单多了 自从有了现实版电报机,妈妈再也不用担心我记不住代码了!!! 再来一发 yes!!That's really I want!! .........................................................(无法再编下去) 对!!代码!![mw_shl_code=cpp,true]// # // # Editor : Lauren from DFRobot // # Date : 17.01.2012 // # Product name: Joystick Module // # Product SKU : DFR0061 // # Version : 1.0 // # Description: // # Modify the Sample code for the Joystick Module // # Connection: // # X-Axis -> Analog pin 2 // # Y-Axis -> Analog pin 3 // # Z-Axis -> Digital pin 4 // # int JoyStick_X = A0; //x int JoyStick_Y = A1; //y int JoyStick_Z = 4; //key int led1=5; int led2=6; int led3=7; int led4=8; int led5=9; void setup() { pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(JoyStick_Z, INPUT); Serial.begin(9600); // 9600 bps } void loop() { int x,y,z; x=analogRead(JoyStick_X); y=analogRead(JoyStick_Y); z=digitalRead(JoyStick_Z); if(x>=900){ digitalWrite(led1,HIGH); } else { digitalWrite(led1,LOW); } if(x<=200){ digitalWrite(led2,HIGH); } else { digitalWrite(led2,LOW); } if(y<=200){ digitalWrite(led4,HIGH); } else { digitalWrite(led4,LOW); } if(y>=900){ digitalWrite(led5,HIGH); } else { digitalWrite(led5,LOW); } if((x<=200)or(x>=900)or(y<=200)or(y>=900)){ digitalWrite(led3,LOW); } else { digitalWrite(led3,HIGH); } if((digitalRead(4))==(HIGH)){ digitalWrite(led3,LOW); } Serial.print(x ,DEC); Serial.print(","); Serial.print(y ,DEC); Serial.print(","); Serial.println(z ,DEC); delay(100); } [/mw_shl_code]连接图比较难弄.... 大家从代码中都可以看出来的对不对呢? 对 好,结束 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed