1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Bài tập lập trình UTEHY

7 3 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 7
Dung lượng 25,18 KB

Nội dung

Bài 1 8 led trực tiếp( 5 quy luật) //Khai bao cac luat dieu khien unsigned char r1[8]={1,0,1,0,1,0,1,0}; unsigned char r2[8]={0,1,0,1,0,1,0,1}; unsigned char r3[8]={1,1,1,1,0,0,0,0}; unsigned char r4[[.]

Bài 1: led trực tiếp( quy luật) //Khai bao cac luat dieu khien unsigned char r1[8]={1,0,1,0,1,0,1,0}; unsigned char r2[8]={0,1,0,1,0,1,0,1}; unsigned char r3[8]={1,1,1,1,0,0,0,0}; unsigned char r4[8]={0,0,0,0,1,1,1,1}; unsigned char r5[8]={1,1,0,0,1,1,0,0}; //Khai bao mang chua cac chan unsigned char pin[8]={2,3,4,5,10,11,12,13}; void setup() { pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(10,OUTPUT); pinMode(11,OUTPUT); pinMode(12,OUTPUT); pinMode(13,OUTPUT); } void loop() { for(int i =0; i=0; i ) { digitalWrite(pin[i],r2[i]); delay(50);//tre 50ms } for(int i =0; i=0; i ) { digitalWrite(pin[i],r2[i]); //delay(200);//tre 200ms } delay(200); for(int i =0; i=0; i ) { digitalWrite(pin[i],r2[i]); //delay(200);//tre 200ms } delay(100); for(int i =0; i=0; i ) { digitalWrite(pin[i],r2[i]); //delay(200);//tre 200ms } delay(100); { for(int i=8; i>=0; i ) digitalWrite(pin[i],r3[i]); //delay(200);//tre 200ms } delay(1000); { for(int i=8; i>=0; i ) digitalWrite(pin[i],r4[i]); //delay(200);//tre 200ms } delay(50); } Bài LED THANH int pinL1 = 0; int pinL2 = 1; int pinL3 = 2; int pinL4 = 3; int pinL5 = 4; int pinL6 = 5; int pinL7 = 6; int pinL8 = 7; int pinL9 = 8; void setup() { pinMode(0,OUTPUT); pinMode(1,OUTPUT); pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); pinMode(7,OUTPUT); pinMode(8,OUTPUT); } void loop() { //0 digitalWrite(0, LOW); digitalWrite(1, LOW); digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); delay(1000); //1 digitalWrite(0, digitalWrite(1, digitalWrite(2, digitalWrite(3, digitalWrite(4, digitalWrite(5, HIGH); LOW); LOW); HIGH); HIGH); HIGH); digitalWrite(6, HIGH); digitalWrite(7, HIGH); digitalWrite(8, HIGH); delay(1000); //2 digitalWrite(0, LOW); digitalWrite(1, LOW); digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, HIGH); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(8, HIGH); delay(1000); //3 digitalWrite(0, LOW); digitalWrite(1, LOW); digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(8, HIGH); delay(1000); //4 digitalWrite(0, HIGH); digitalWrite(1, LOW); digitalWrite(2, LOW); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, HIGH); digitalWrite(8, HIGH); delay(1000); //5 digitalWrite(0, LOW); digitalWrite(1, HIGH); digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, HIGH); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, digitalWrite(8, delay(1000); //6 digitalWrite(0, digitalWrite(1, digitalWrite(2, digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(7, digitalWrite(8, delay(1000); //7 digitalWrite(0, digitalWrite(1, digitalWrite(2, digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(7, digitalWrite(8, delay(1000); //8 digitalWrite(0, digitalWrite(1, digitalWrite(2, digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(7, digitalWrite(8, delay(1000); //9 digitalWrite(0, digitalWrite(1, digitalWrite(2, digitalWrite(3, digitalWrite(4, digitalWrite(5, digitalWrite(6, digitalWrite(7, LOW); HIGH); LOW); HIGH); LOW); LOW); LOW); LOW); LOW); LOW); HIGH); LOW); LOW); LOW); HIGH); HIGH); HIGH); HIGH); HIGH); HIGH); LOW); LOW); LOW); LOW); LOW); LOW); LOW); LOW); HIGH); LOW); LOW); LOW); LOW); HIGH); LOW); LOW); LOW); digitalWrite(8, HIGH); delay(1000); } BÀI ĐẾM TỪ 00 ĐẾN 99 #define DATA //DS #define LATCH //ST_CP #define CLOCK //SH_CP int giaima7doan[]{252,96,218,242,102,182,190,224,254,246}; // int num=0; void hienthi2so(int num) { int a = num/10; int b = num%10; shiftOut(DATA, CLOCK, LSBFIRST, giaima7doan[b]); shiftOut(DATA, CLOCK, LSBFIRST, giaima7doan[a]); } void setup() { pinMode(LATCH, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(DATA, OUTPUT); } void loop() { for( int i = ; i

Ngày đăng: 20/06/2023, 23:02

w