Changes between Version 2 and Version 3 of SujetTP6-2016


Ignore:
Timestamp:
Mar 18, 2016, 8:57:37 AM (9 years ago)
Author:
franck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SujetTP6-2016

    v2 v3  
    1414== Exécution ''multi-tâches'' ==
    1515
     16{{{!#c
     17#define MAXTIMER 16
     18long waitForTimer[MAXTIMER];
     19int waitFor(int timer, long period){
     20  long newTime = micros() / period;
     21  int delta = newTime - waitForTimer[timer];
     22  if ( delta ) {
     23    waitForTimer[timer] = newTime;
     24  }
     25  return delta;
     26}
     27
     28void setup() {
     29  pinMode(13,OUTPUT);
     30  Serial.begin(115200);
     31}
     32
     33void Led(int timer, long period, int led) {
     34  static int val = 0;
     35  if (!waitFor(timer,period)) return;
     36  digitalWrite(13,val);
     37  val = 1 - val;
     38}
     39
     40void Mess(int timer, long period, const char * mess) {
     41  if (!waitFor(timer,period)) return;
     42  Serial.println(mess);
     43}
     44
     45void loop() {
     46  Led (0,100000,13);
     47  Mess(1,1000000,"bonjour");
     48}
     49}}}
    1650== Lecture de la luminosité ==
    1751