Программирование - это просто
Advertisement
arrow arrow . arrow . 4. C Arduino
06.02.2023 .
1:
C#
Delphi
Web-
Excel-
.
. 4. C Arduino E-mail
megabax   
15.11.2020 .
New Page 1

. 4. C Arduino

" ". " ", , . . , -. Arduino .  , , . , , .

, " " . , , . , , , . . , delay. , :

#define count 16 // ,

 

struct node {

    bool light; //

    int led; //

    int delay_mils; //,

} a[count] = {{true, 10, 300}, {true, 11, 300}, {true, 12, 300}, {true,13, 300}, {false,13,1000}, {false,12,1000}, {false,11,1000}, {false, 10,1000}, {true, 10,500},

          {false, 10,200}, {true,11,500},

          {false,11,200}, {true,12,500}, {false,12,200}, {true,13,500}, {false,13,1500}}; 

 

unsigned long previousMillis = 0;  //

int i=0; //

 

void setup() {

  // put your setup code here, to run once:

  pinMode(10, OUTPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);

  pinMode(13, OUTPUT);

}

 

void loop() {

  unsigned long currentMillis = millis(); //

  if(currentMillis-previousMillis<a[i].delay_mils) return; // -

  if(a[i].light)

  {

     digitalWrite(a[i].led, HIGH); // ; led - , - (HIGH) (LOW)

  }

  else

  {

       digitalWrite(a[i].led, LOW); // ; led - , - (HIGH) (LOW)

  }

  i++;

  if(i>=count) i=0;

  previousMillis=currentMillis;

}

 

? , , , . , : ? , " ", - , , , - . , delay, . , , .

C Arduino.  - random() - . :

#define delay_max 500 //

 

unsigned long previousMillis = 0;  //

int delay_mils=random(0,delay_max); //

 

void setup() {

  // put your setup code here, to run once:

  pinMode(10, OUTPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);

  pinMode(13, OUTPUT);

}

 

void loop() { 

  unsigned long currentMillis = millis(); //

  if(currentMillis-previousMillis<delay_mils) return; // -

  if(random(10)>5)

  {

        digitalWrite(random(10,14), HIGH); // ; led - , - (HIGH) (LOW)

  }

  else

  {

       digitalWrite(random(10,14), LOW); // ; led - , - (HIGH) (LOW)

  }

  delay_mils=random(0,delay_max); //

  previousMillis=currentMillis;

}

 

, , .

 
. »
 
© 2023 Программирование - это просто
Joomla! - , GNU/GPL.
© 2005-2008 Joom.Ru - Joomla!
Design by Mamboteam.com | Powered by Mambobanner.de
  .