TA的每日心情 | 开心 2020-2-14 12:16 |
---|
签到天数: 827 天 连续签到: 1 天 [LV.10]以坛为家III
|
接上一篇帖子
四周年庆-【赚周年币】fireduino-基于labview的双机通信-上位机-爱板网论坛 - 电子工程师学习交流园地 https://www.cirmall.com/bbs/thread-59343-1-1.html
fireduino程序如下
- void setup()
- {
- Wire.begin(10); // join i2c bus with address #4
- Wire.onRequest(requestEvent);
- Wire.onReceive(receiveEvent); // register event
- pinMode(13,OUTPUT); //if use fireduino,should be pinMode(4,OUTPUT);
- Serial.begin(9600); // start serial for output
- }
- void loop()
- {
- delay(100);
- }
- // function that executes whenever data is received from master
- // this function is registered as an event, see setup()
- void receiveEvent(int howMany)
- {
- while(0 < Wire.available()) // loop through all but the last
- {
- byte c = Wire.read(); // receive byte as a character
- if(c==1)
- {
- digitalWrite(13,LOW);
- }
- else if(c==0)
- {
- digitalWrite(13,HIGH);
- }
- else
- {
- digitalWrite(13,HIGH);
- }
- Serial.print(c); // print the character
- }
- //int x = Wire.read(); // receive byte as an integer
- //Serial.println(x); // print the integer // print the integer
- }
- void requestEvent()
- {
- Wire.write(i++);
- if(i > 255) // loop through all but the last
- {
- i=0;
- }
- }
复制代码 程序中定义了两个函数:数据接收事件和请求事件
注意:
1、fireduino默认115200波特率,需要在其相关头文件修改;或者修改arduino初始化函数,如下
2、也可以使用fireduino的D4输出控制用户LED,注意是共阳极,低电平亮
|
评分
-
查看全部评分
|