2020年8月2日日曜日
arduino 作ってみました
プログラムです。
--------------------------------
long randNumber;
int a;
int b;
int c;
int d;
void setup(){
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
// pinMode(8,OUTPUT);
// pinMode(1,OUTPUT);
randomSeed(analogRead(0));
}
void loop() {
randNumber = random(10, 20);
b = randNumber;
for(int i = 0; i<=b;i++){
randNumber = random(3, 8);
a = randNumber;
digitalWrite(a,HIGH);
delay(100);
digitalWrite(a,LOW);
delay(100);
}
digitalWrite(5,HIGH);
delay(3000);
digitalWrite(5,LOW);
randNumber = random(1, 3);
c = randNumber;
if ( c == 1 ){
digitalWrite(6,HIGH);
delay(1000);
digitalWrite(6,LOW);
delay(1000);
randNumber = random(1, 3);
d = randNumber;
if ( d == 1 ){
digitalWrite(7,HIGH);
delay(3000);
digitalWrite(7,LOW);
delay(1000);
}else
{
digitalWrite(5,HIGH);
delay(3000);
digitalWrite(5,LOW);
delay(1000);
}
}else
{
digitalWrite(4,HIGH);
delay(1000);
digitalWrite(4,LOW);
delay(1000);
randNumber = random(1, 3);
d = randNumber;
if ( d == 1 ){
digitalWrite(3,HIGH);
delay(3000);
digitalWrite(3,LOW);
delay(1000);
}else
{
digitalWrite(5,HIGH);
delay(3000);
digitalWrite(5,LOW);
delay(1000);
}
}
}
----------------------------------------
--------------------------------
long randNumber;
int a;
int b;
int c;
int d;
void setup(){
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
// pinMode(8,OUTPUT);
// pinMode(1,OUTPUT);
randomSeed(analogRead(0));
}
void loop() {
randNumber = random(10, 20);
b = randNumber;
for(int i = 0; i<=b;i++){
randNumber = random(3, 8);
a = randNumber;
digitalWrite(a,HIGH);
delay(100);
digitalWrite(a,LOW);
delay(100);
}
digitalWrite(5,HIGH);
delay(3000);
digitalWrite(5,LOW);
randNumber = random(1, 3);
c = randNumber;
if ( c == 1 ){
digitalWrite(6,HIGH);
delay(1000);
digitalWrite(6,LOW);
delay(1000);
randNumber = random(1, 3);
d = randNumber;
if ( d == 1 ){
digitalWrite(7,HIGH);
delay(3000);
digitalWrite(7,LOW);
delay(1000);
}else
{
digitalWrite(5,HIGH);
delay(3000);
digitalWrite(5,LOW);
delay(1000);
}
}else
{
digitalWrite(4,HIGH);
delay(1000);
digitalWrite(4,LOW);
delay(1000);
randNumber = random(1, 3);
d = randNumber;
if ( d == 1 ){
digitalWrite(3,HIGH);
delay(3000);
digitalWrite(3,LOW);
delay(1000);
}else
{
digitalWrite(5,HIGH);
delay(3000);
digitalWrite(5,LOW);
delay(1000);
}
}
}
----------------------------------------
2020年8月1日土曜日
arduino 乱数を発生させる
-----------------------------
long randNumber;
void setup(){
Serial.begin(9600);
randomSeed(analogRead(0));
}
void loop() {
randNumber = random(3); // 0から299の乱数を生成
Serial.println(randNumber);
randNumber = random(100, 200); // 10から19の乱数を生成
Serial.println(randNumber);
delay(2000);
}
---------------------------------
使いやすいです。
http://www.musashinodenpa.com/arduino/ref/index.php?f=0&pos=2901
long randNumber;
void setup(){
Serial.begin(9600);
randomSeed(analogRead(0));
}
void loop() {
randNumber = random(3); // 0から299の乱数を生成
Serial.println(randNumber);
randNumber = random(100, 200); // 10から19の乱数を生成
Serial.println(randNumber);
delay(2000);
}
---------------------------------
使いやすいです。
http://www.musashinodenpa.com/arduino/ref/index.php?f=0&pos=2901
登録:
投稿 (Atom)