我想知道2问题:
1.PWM设置引脚输出是否可以不要
2.if(mark==1) 是否与前面例子中 if(comdata.length()>0)等同
另外ctrl+回车就发帖了,怎么不能编辑修改,造成连发三次。
感谢楼主,收藏!
目前通过自学遇到以下几个问题,求高手帮帮忙,在此先谢谢了~~
1.通过LABVIEW 的布尔按钮控制ARDUINO的D2-D13上LED灯的开关;
2.通过ARDUINO的D2-D13的开工量控制LABVIEW的显示状况;(比如D2接按钮1 ,控制D8接的LED灯,当按钮1按下时,LED灯亮,LABVIEW 要显示)
以上2个问题我纠结了好久,一直没有调试成功
这个不错,我喜欢收藏了。{:soso_e179:}
飞翔的红猪 发表于 2012-6-24 10:39 static/image/common/back.gif
这个程序处理的是字节型的数据,用于控制或者显示到LCD都还简单的,但是如果接收传送的是整形乃至浮点的时候 ...
简单,2个方式,一个是按照科学计数法来玩, 比如123456=1.23456*100000 你传输可以传输
123456,100000; 处理的时候把第一组数据接到之后第一位数前面加小数点*第二组数
还有一种就是第二位标定小数点位置(可以约定小数位 比如10带代表前面是整数那么9就说明1位小数 0就意味着9位小数,11代表后面1个0) 自己按照需求就好了嘛。这样搞法 可以标定很小的小数
正在发愁呢,多谢楼主的帖子
坏鸟 发表于 2011-12-2 01:56 static/image/common/back.gif
处理PC串口输入数据的方法真的有很多很多种.......我自己就研究了三种。
/*
Reading a serial ASCII-encoded string.
This sketch demonstrates the Serial parseInt() function.
It looks for an ASCII string of comma-separated values.
It parses them into ints, and uses those to fade an RGB LED.
Circuit: Common-anode RGB LED wired like so:
* Red cathode: digital pin 3
* Green cathode: digital pin 5
* blue cathode: digital pin 6
* anode: +5V
created 13 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
// pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
// look for the newline. That's the end of your
// sentence:
if (Serial.read() == '\n') {
// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
red = 255 - constrain(red, 0, 255);
green = 255 - constrain(green, 0, 255);
blue = 255 - constrain(blue, 0, 255);
// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
// print the three numbers in one string as hexadecimal:
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
}
}
}
楼主的思路不错,但以上是IDE自带的例子,比楼主简单的多。
受教了,正遇到这个问题呢,楼组很强大!:lol
好啊啊啊啊啊
坏鸟 发表于 2011-12-2 01:56 static/image/common/back.gif
处理PC串口输入数据的方法真的有很多很多种.......我自己就研究了三种。
请问:
我的PC端发出来的是hex格式的数据,我的数据是“7F 00 # 10 80 01 # 2F # 2F # 00 # 7F”这么一个格式,#号代表的位数不一定,我应该怎么写代码,才能把这些#代表的东西取出来呢?
看了很多资料,都没有一个头绪。
xietu 发表于 2012-8-18 21:53 static/image/common/back.gif
//我最近正好有用到这个代码,很感谢,不过我需要输入负数,所以加了些改动;我刚接触arduino,编码还不熟, ...
++j;和J++ 最后J的值都+1的
读取串口数据真的很难啊
顶!!!!!!!!!!!!!!!!!:)