|
|
本帖最后由 mengfeng009 于 2015-9-10 13:11 编辑
昨天在网上购买了ocrobot s-100,今天看了下觉得用料足物超所值.这么好的东西缺少教程,教师节做一回老师吧.发一个吧.
- /*
- Relay_matrix
- It is a demo for using of Relay module
- SIMON@FOX 2015.SEP.10
- */
-
- // X = input in PLC, we use X for input .
- // give it a name:
- int X1 = 12; //1# opticalcoupler @ 12
- int X2 = 13;
- int X3 = 14;
- int X4 = 15;
- int X5 = 16;
- int X6 = 17;
- int X7 = 18;
- int X8 = 19; //8# opticalcoupler @ 19
-
-
- // Y = Output in PLC, we use Y for output .
- // give it a name:
- int Y1 = 2;//1# relay
- int Y2 = 3;
- int Y3 = 4;
- int Y4 = 5;
- int Y5 = 6;
- int Y6 = 7;
- int Y7 = 8;
- int Y8 = 9;//8# relay
- // the setup routine runs once when you press reset:
- void setup() {
-
- // initialize the digital pin as an output.
- pinMode(Y1, OUTPUT); //1# relay
- pinMode(Y2, OUTPUT);
- pinMode(Y3, OUTPUT);
- pinMode(Y4, OUTPUT);
- pinMode(Y5, OUTPUT);
- pinMode(Y6, OUTPUT);
- pinMode(Y7, OUTPUT);
- pinMode(Y8, OUTPUT); //8# relay
- // initialize the digital pin as an input.
- pinMode(X1, INPUT); //1# relay
- pinMode(X2, INPUT);
- pinMode(X3, INPUT);
- pinMode(X4, INPUT);
- pinMode(X5, INPUT);
- pinMode(X6, INPUT);
- pinMode(X7, INPUT);
- pinMode(X8, INPUT); //8# relay
-
- // RELAY TEST BEGIN
- int i =0;
- while (i<8)
- {
- digitalWrite(i+2, HIGH); // GIVE THE COIL POWER
- delay(300); //
- digitalWrite(i+2, LOW); //
- delay(300);
- i++; // wait for a second
- }
- // RELAY TEST END
- Serial.begin(9600);
- Serial.println ("INIT FINISHED");
- Serial.println ("PROGRAME STARTED ");
- }
- // the loop routine runs over and over again forever:
- void loop() {
- if (digitalRead(X1))
- {
- Serial.println ("X1=HIGH ");
- digitalWrite(Y1, HIGH); // GIVE THE COIL POWER
- delay(300); //
- }
- else
- {
- Serial.println ("X1=LOW ");
- digitalWrite(Y1, LOW); // GIVE THE COIL POWER
- delay(300); //
- }
-
-
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|