int s[5];
int g=1;
int j=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int len=sizeof(s)/sizeof(int);
if (Serial.available()>0)
{
if (j<len)
{
s[j]=Serial.readString().toInt();
Serial.println("input ["+(String)g+"] element:"+s[j]);
if(g==len)
{
Serial.println("finish input...end");
for (int y=0;y<len;y++)
{
Serial.println(s[y]);
}
}
else
{
g++;
j++;
}
}
}
}
====================================
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int a[2][3]={{10,20,30},{40,50,60}}; // a[y][x]
int len1=sizeof(a)/sizeof(int); //所有元素
int len2=sizeof(a[0])/sizeof(int); //y個元素
int len0=len1/len2; //x元素
Serial.println("len1:"+(String)len1);
Serial.println("len2:"+(String)len2);
Serial.println("len0:"+(String)len0);
}
============================
輸出
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int a[2][3]={{10,20,30},{40,50,60}};
int len1=sizeof(a)/sizeof(int);
int len2=sizeof(a[0])/sizeof(int);
int len0=len1/len2;
for(int i=0;i<len0;i++)
{
for (int j=0;j<len2;j++)
{
Serial.println("a["+(String)i+"]["+(String)j+"]="+a[i][j]);
}
}
}
====================================================
七段顯示器
int sp[10][7]={{1,1,1,1,1,1,0},
{0,1,1,0,0,0,0},
{1,1,0,1,1,0,1},
{1,1,1,1,0,0,1},
{0,1,1,0,0,1,1},
{1,0,1,1,0,1,1},
{1,0,1,1,1,1,1},
{1,1,1,0,0,0,0},
{1,1,1,1,1,1,1},
{1,1,1,1,0,1,1}};
int k;
void setup() {
// put your setup code here, to run once:
k=0;
for(int i=5;i<=11;i++)
{
pinMode(i,OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
for(int j=0;j<7;j++)
{
digitalWrite(j+5,sp[k][j]);
}
delay(2000);
k++;
if(k==10)
{
k=0;
}
}
=================================================
int sp[10][7]={{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},{0,1,1,0,0,1,1},{1,0,1,1,0,1,1},{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};
int d[4]={1,3,1,4};
int k;
void setup() {
// put your setup code here, to run once:
k=0;
for(int i=5;i<=11;i++)
{
pinMode(i,OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
for(int j=0;j<7;j++)
{
digitalWrite(j+5,sp[d[k]][j]);
}
delay(2000);
k++;
if(k==4)
{
k=0;
}
}
===================================
int sp[10][7]={{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},{0,1,1,0,0,1,1},{1,0,1,1,0,1,1},{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};
int d[3]={5,2,0};
int k;
void setup() {
// put your setup code here, to run once:
k=0;
for(int i=5;i<=11;i++)
{
pinMode(i,OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
for(int j=0;j<7;j++)
{
digitalWrite(j+5,sp[d[k]][j]);
}
delay(2000);
k++;
if(k==3)
{
k=0;
}
}
=============================================
輸入
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int a[2][3];
int len1=sizeof(a)/sizeof(int);
int len2=sizeof(a[0])/sizeof(int);
int len=len1/len2;
int k=10;
for(int i=0;i<len;i++)
{
for (int j=0;j<len2;j++)
{
a[i][j]=k;
k++;
}
}
for(int i=0;i<len;i++)
{
for (int j=0;j<len2;j++)
{
Serial.println(a[i][j]);
}
}
}
====================================================
沒有留言:
張貼留言