找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2477|回复: 0
打印 上一主题 下一主题
收起左侧

arduino如何从串口监视器用发送字符串

[复制链接]
跳转到指定楼层
楼主
我从串口监视器发送 数字123,arduino得到的是1,2,3,独立的三个数字 。
如果需要发送一个字符串怎么发送?arduino又要怎样接收字符串?
截图:


代码:
/*
  verify the function and serial port.
*/

int isodd(int a )
{
  if (a % 2 == 0)
    return 1;
  else
    return 0;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(13, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available())
  {
    int a = Serial.read() - '0';

    if (isodd(a))
    {
      digitalWrite(13, HIGH);
      Serial.print(a);
      Serial.println(" 是偶数");
    }
    else
    {
      Serial.print(a);
      Serial.println(" 是奇数");
      digitalWrite(13, LOW);
    }
  }
}

通信截图.png (5.06 KB, 下载次数: 48)

通信截图.png
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表