資料型態 陣列[]={值1,......}
對映函式 map(可變電阻,值1,值2,值3,值4);
int srv=(0,1023,1,4);
const int led[5]={3,4,5,6,7};
int va=A0;
int kv;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for(int i=0;i<5;i++)
{
pinMode(led[i],OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
int sv=analogRead(va);
kv=map(sv,0,1023,0,4);
//Serial.println(kv);
for(int i=0;i<5;i++)
{
digitalWrite(led[i],LOW);
}
digitalWrite(led[kv],HIGH);
delay(1000);
}
================================
使用if
int led1=3;
int led2=4;
int led3=5;
int led4=6;
int led5=7;
int srv;
void setup() {
// put your setup code here, to run once:
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
srv=analogRead(A0);
srv=map(srv,0,1000,0,4);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
digitalWrite(led5,LOW);
if (srv==0)
{
digitalWrite(led1,HIGH);
}
else if(srv==1)
{
digitalWrite(led2,HIGH);
}
else if(srv==2)
{
digitalWrite(led3,HIGH);
}
else if(srv==3)
{
digitalWrite(led4,HIGH);
}
else if(srv==4)
{
digitalWrite(led5,HIGH);
}
delay(1000);
}
==================================
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int k[6]={11,12,13,14,15,16};
int len=sizeof(k);//12
Serial.println(len);
}
====================
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int k[6]={11,12,13,14,15,16};
int len=sizeof(k)/sizeof(int);//6
Serial.println(len);
}
======================================
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int a[5]={10,20,30,40,50};
int len=sizeof(a)/sizeof(int);
for (int i=0;i<len;i++)
{
Serial.println(a[i]);//
}
for (int j=len-1;j>=0;j--)
{
Serial.println(a[j]);//
}
}
=============================
求極大值
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int a[5]={67,6,99,12,89};
int len=sizeof(a)/sizeof(int);
int max=0;
for (int i=0;i<len;i++)
{
if (max<a[i])
{
max=a[i];
}
}
Serial.println(max);
}
=============================================
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int a[5]={67,6,99,12,89};
int len=sizeof(a)/sizeof(int);
int min=a[0];
for (int i=0;i<len;i++)
{
if (min>a[i])
{
min=a[i];
}
}
Serial.println(min);
}
============================
int b[5];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for(int i=10;i<=14;i++)
{
b[i-10]=i;
}
int len=sizeof(b)/sizeof(int);
for (int i=0;i<len;i++)
{
Serial.println(b[i]);
}
}
=================================
1-1 電的特性:如物質的結構、原子的結構及電的產生等求極大值
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int a[5]={67,6,99,12,89};
int len=sizeof(a)/sizeof(int);
int max=0;
for (int i=0;i<len;i++)
{
if (max<a[i])
{
max=a[i];
}
}
Serial.println(max);
}
=============================================
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int a[5]={67,6,99,12,89};
int len=sizeof(a)/sizeof(int);
int min=a[0];
for (int i=0;i<len;i++)
{
if (min>a[i])
{
min=a[i];
}
}
Serial.println(min);
}
============================
int b[5];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for(int i=10;i<=14;i++)
{
b[i-10]=i;
}
int len=sizeof(b)/sizeof(int);
for (int i=0;i<len;i++)
{
Serial.println(b[i]);
}
}
=================================
1-2 常用單位:如焦耳(J)、庫侖(C)、伏特(V)、安培(A)及瓦特(W)等
1-3 能量:包含能量定義、能量轉換、效率、單位轉換等
1-4 電荷:包含電荷定義、電荷特性、庫侖定律等
1-5 電壓:包含電壓定義、電位與電位差、電動勢、電壓降及端電壓等
1-6 電流:包含電流定義、電流速率等
1-7 功率:包含功率定義、功及功率等
1-8 基本元件及符號認識
沒有留言:
張貼留言