Tinkercad - Arduino模擬器
下載 Arduino模擬器
https://drive.google.com/file/d/16i7XchvSSXDzYpTmrAsszMeLXXiaG8-u/view?usp=sharing
使用陣列來完成
// 定義LED的腳位
int LED[]={7,6,5,4,3};
void setup()
{
// 將LED腳位設置為輸出
for(int i=0;i<5;i=i+1){
pinMode(LED[i], OUTPUT);
}
}
void loop()
{
// 這五個LED燈依序亮燈,每個燈持續1秒
for(int i=0;i<5;i=i+1){
digitalWrite(LED[i], HIGH);
delay(1000);
digitalWrite(LED[i], LOW);
}
}
-----------------20240703---------------------
int pins=7;
void setup()
{
pinMode(pins, OUTPUT);
}
void loop()
{
digitalWrite(pins, HIGH);
int v[]={262,294,330,349,392,440,492};
int d=250;
int s[]={1, 1, 5, 5, 6, 6, 5, 4, 4, 3,
3, 2, 2, 1, 5, 5, 4, 4, 3, 3,
2, 5, 5, 4, 4, 3, 3, 2, 1, 1,
5, 5, 6, 6, 5, 4, 4, 3, 3, 2, 2, 1
};
for(int i=0;i<sizeof(s)/sizeof(s[0]);i=i+1){
tone(pins, v[s[i] - 1], d);
delay(2 * d);
}
noTone(pins); // 停止音符
digitalWrite(pins, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
-----------------------------------------------
int pins=7;
void setup()
{
pinMode(pins, OUTPUT);
}
void loop()
{
digitalWrite(pins, HIGH);
int v[]={262,294,330,349,392,440,492};
int d=100;
int s[]={1, 1, 5, 5, 6, 6, 5,
4, 4, 3, 3, 2, 2, 1,
5, 5, 4, 4, 3, 3, 2,
5, 5, 4, 4, 3, 3, 2,
1, 1, 5, 5, 6, 6, 5,
4, 4, 3, 3, 2, 2, 1
};
for(int i=0;i<sizeof(s)/sizeof(s[0]);i=i+1){
if(i==6 or i==13){
tone(pins, v[s[i] - 1], d);
delay(2 * d);
delay(100);
}else{
tone(pins, v[s[i] - 1], d);
delay(2 * d);
}
}
noTone(pins); // 停止音符
digitalWrite(pins, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
-----------------------------------------------------------
//兩個LED燈+蜂鳴器
int pin7=7;
int pin6=6;
void setup()
{
pinMode(pin7, OUTPUT);
pinMode(pin6, OUTPUT);
}
void loop()
{
digitalWrite(pin7, HIGH);
digitalWrite(pin6, HIGH);
int v[]={262,294,330,349,392,440,492};
int d=100;
int s[]={1, 1, 5, 5, 6, 6, 5,
4, 4, 3, 3, 2, 2, 1,
5, 5, 4, 4, 3, 3, 2,
5, 5, 4, 4, 3, 3, 2,
1, 1, 5, 5, 6, 6, 5,
4, 4, 3, 3, 2, 2, 1
};
for(int i=0;i<sizeof(s)/sizeof(s[0]);i=i+1){
if(i==6 or i==13){
tone(pin7, v[s[i] - 1], d);
delay(2 * d);
delay(1000);
}else{
tone(pin7, v[s[i] - 1], d);
delay(2 * d);
}
}
noTone(pin7); // 停止音符
digitalWrite(pin6, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
------20240705-------
-------------------------
int pins=7;
int pina=A0;
int LED=5;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
int v=analogRead(pins);
Serial.println(v);
if (v > 400) { // 設定一個閾值,當觸碰時LED發亮
digitalWrite(LED, HIGH); // 點亮LED
} else {
digitalWrite(LED, LOW); // 關閉LED
}
delay(1000);
}
熱門評論
// 定義LED的腳位
int LED[]={2,3,4,5,6};
void setup()
{
// 將LED腳位設置為輸出
for(int i=0;i<5;i=i+1){
pinMode(LED[i], OUTPUT);
}}
void loop()
{
// 這五個LED燈依序亮燈,每個燈持續1秒
for(int i=0;i<5;i=i+1){
digitalWrite(LED[i], HIGH);
delay(150);
digitalWrite(LED[i], LOW);
}
}
小星星音符
1,1,5,5,6,6,5,4,4,3,3,2,2,1,5,5,4,4,3,3,2,5,5,4,4,3,3,2,1,1,5,5,6,6,5,4,4,3,3,2,2,1
Copyright © 2019 Digitgeek.Net ☺