圣源电子制作

 找回密码
 立即注册
查看: 7455|回复: 0

Ardunio 入门教程-实验六 摩尔斯电码SOS求救信号

[复制链接]
发表于 2012-5-12 15:01:47 | 显示全部楼层 |阅读模式
   Ardunio 入门教程-实验六 摩尔斯电码SOS求救信号

实验用到的元件
TD776_IMG_3993.JPG
实验用到的元件 ,一个LED,2根杜邦线,一块实验板。
原理图
20120512144605.png



LED长脚的为正,短脚为负极。

连接图
TD776_IMG_3994.JPG
LED的正极连接 IO口12,LED负极连接电阻,电阻的另外一端接GND.

实验演示视频:



代码
  1. int ledPin = 12;
  2. int durations[] = {200, 200, 200, 500, 500, 500, 200, 200, 200};

  3. void setup() // run once, when the sketch starts
  4. {
  5. pinMode(ledPin, OUTPUT); // sets the digital pin as output
  6. }

  7. void loop() // run over and over again
  8. {
  9. for (int i = 0; i < 9; i++)
  10. {
  11. flash(durations[i]);
  12. if (i == 2)
  13. {
  14. delay(300);
  15. }
  16. }
  17. delay(1000); // wait 1 second before we start again
  18. }

  19. void flash(int duration)
  20. {
  21. digitalWrite(ledPin, HIGH);
  22. delay(duration);
  23. digitalWrite(ledPin, LOW);
  24. delay(duration);
  25. }
复制代码
回复

使用道具 举报

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

本版积分规则

QQ|手机版|联系我们|闽公网安备 35012102000020号|圣源电子 ( 闽ICP备11020110号 )

GMT+8, 2024-3-29 04:59 , Processed in 0.050542 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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