Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arduino单片机基础 周弋 11307110106.

Similar presentations


Presentation on theme: "Arduino单片机基础 周弋 11307110106."— Presentation transcript:

1 Arduino单片机基础 周弋

2 ARDUINO = 基于单片机并且开放源码的硬件平台 + 为ARDUINO板编写程序的开发环境

3 Arduino的优点 便宜 跨平台 简易的编程环境 软件开源并可扩展 硬件开源并可扩展

4 Arduino的基本性能配置 Digital I/O 数字输入/输出端口 0—13。 Analog I/O 模拟输入/输出端口 0-5。
支持 ICSP 下载,支持 TX/RX。 输入电压:USB 接口供电或者 5V-12V 外部电源供电。 输出电压:支持 3.3V/5V DC 输出。 处理器:使用 Atmel Atmega168/328 处理器。

5 按键控制LED亮灭

6 #define LED 11 #define KEY 7 int val; void setup() { pinMode(LED,OUTPUT); pinMode(KEY,INPUT); } void loop() val=digitalRead(KEY); if(val==LOW) { digitalWrite(LED,LOW);} else { digitalWrite(LED,HIGH);}

7 去抖动原理和松手检测原理 if(val==LOW) { delay(20); digitalWrite(LED,LOW); }
void loop() { ScanKey(); if(KEY_NUM == 1) digitalWrite(LED,!digitalRead(LED)); }

8 void ScanKey() { KEY_NUM = 0; if(digitalRead(KEY) == HIGH) delay(20); KEY_NUM = 1; while(digitalRead(KEY) == LOW); }

9 LED七彩跳变

10 void loop() { unsigned int i; for(i = 0 ; i < 7 ; i++) Change_Color(i); delay(1000); } void Change_Color(unsigned char data_color) switch(data_color) case Color_R: digitalWrite(LED_R,LOW); digitalWrite(LED_G,HIGH); digitalWrite(LED_B,HIGH); break; ……

11 点阵实验

12 unsigned char table1[8][8] = { 0,0,0,0,0,0,0,0, 0,1,1,0,0,1,1,0, 1,1,1,1,1,1,1,1, 0,1,1,1,1,1,1,0, 0,0,1,1,1,1,0,0, 0,0,0,1,1,0,0,0, }; unsigned char table2[8][8] = 0,0,1,0,0,1,0,0,

13 void loop() { for(int i = 0 ; i < 100 ; i++) Display(table1); } for(int i = 0 ; i < 50 ; i++) Display(table2);

14 void Display(unsigned char dat[8][8]) { digitalWrite(L1,LOW); digitalWrite(H1,dat[0][0]); digitalWrite(H2,dat[1][0]); digitalWrite(H3,dat[2][0]); digitalWrite(H4,dat[3][0]); digitalWrite(H5,dat[4][0]); digitalWrite(H6,dat[5][0]); digitalWrite(H7,dat[6][0]); digitalWrite(H8,dat[7][0]); delay(1); Clear(); …… }

15 蜂鸣器 有源/无源 #define NOTE_D1 294 #define HALF 0
蜂鸣器 有源/无源 #define NOTE_D1 294 #define HALF 0.5 int tune[] ={} float duration[]={} void loop() { for(int x=0;x<length;x++) tone(tonePin,tune[x]); delay(400*duration[x]); noTone(tonePin); } delay(5000);

16 虚拟鼠标实验 Mouse.move(-40, 0); Mouse.move(40, 0); Mouse.click(MOUSE_LEFT);

17 谢谢!


Download ppt "Arduino单片机基础 周弋 11307110106."

Similar presentations


Ads by Google