Outils d'utilisateurs

Outils du Site


projets:arduino_beginner

Différences

Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.

Lien vers cette vue

projets:arduino_beginner [2019/09/04 14:32]
stfablab
projets:arduino_beginner [2019/10/15 15:23] (Version actuelle)
stfablab
Ligne 137: Ligne 137:
   Serial.println();   Serial.println();
 } }
 +
 +/*Masks,
 +  How to get a bit : (x&(1<<i))!=0
 +  How to set a bit : x|(1<<i)
 +  How to clear a bit : x&(~(1<<i))
 +  carrefour numérique@cité des sciences et de l'industrie, Paris
 +  With no warranty
 +*/
 +
 +int b = B11011101;
 +int c = 1;
 +int d = 2;
 +
 +void setup() {
 +  // put your setup code here, to run once:
 +  Serial.begin(9600);
 +  Serial.println("Hello!");
 +  Serial.println();
 +}
 +
 +void loop() {
 +  // put your main code here, to run repeatedly:
 +  if (c != d) {
 +    d = c;
 +    Serial.print("a = "); Serial.println(a, BIN);
 +    Serial.print("b = "); Serial.println(b, BIN);
 +    Serial.println();
 +    (b & (1 << 7)) != 0; Serial.print("Keeping b bit n°8 : "); Serial.println((b & (1 << 7)) != 0, BIN);
 +    (b & (1 << 6)) != 0; Serial.print("Keeping b bit n°7 : "); Serial.println((b & (1 << 6)) != 0, BIN);
 +    (b & (1 << 5)) != 0; Serial.print("Keeping b bit n°6 : "); Serial.println((b & (1 << 5)) != 0, BIN);
 +    (b & (1 << 4)) != 0; Serial.print("Keeping b bit n°5 : "); Serial.println((b & (1 << 4)) != 0, BIN);
 +    (b & (1 << 3)) != 0; Serial.print("Keeping b bit n°4 : "); Serial.println((b & (1 << 3)) != 0, BIN);
 +    (b & (1 << 2)) != 0; Serial.print("Keeping b bit n°3 : "); Serial.println((b & (1 << 2)) != 0, BIN);
 +    (b & (1 << 1)) != 0; Serial.print("Keeping b bit n°2 : "); Serial.println((b & (1 << 1)) != 0, BIN);
 +    (b & (1 << 0)) != 0; Serial.print("Keeping b bit n°1 : "); Serial.println((b & (1 << 0)) != 0, BIN);
 +    Serial.println();
 +    b = b | (1 << 5); Serial.println("Setting b bit n°6 with 1 : "); Serial.println(b, BIN);
 +    Serial.println();
 +    b = b & (~(1 << 3)); Serial.println("Clearing b bit n°4 with 0 : "); Serial.println(b, BIN);
 +  }
 +}
 +
 ===== Photos ===== ===== Photos =====
 <!-- Quelques photos du rendu final du projet, mais aussi si c'est possible des differentes etapes si elle n'ont pas déja été documentées visuellement --> <!-- Quelques photos du rendu final du projet, mais aussi si c'est possible des differentes etapes si elle n'ont pas déja été documentées visuellement -->
projets/arduino_beginner.1567600364.txt.gz · Dernière modification: 2019/09/04 14:32 par stfablab