Diferencia entre revisiones de «bit()»

De ArduWiki
Saltar a: navegación, buscar
(Referencias)
(Ejemplo 3)
 
(No se muestran 5 ediciones intermedias del mismo usuario)
Línea 41: Línea 41:
 
void loop(){
 
void loop(){
 
   //Nada
 
   //Nada
 +
}
 +
</syntaxhighlight>
 +
 +
== Ejemplo 3 ==
 +
Parpadea el LED a bordo.
 +
 +
<syntaxhighlight lang="c++">
 +
void setup() {
 +
  DDRB = DDRB | bit(5);    //Configura el pin digital 13 (bit 5) como OUTPUT, no altera el resto.
 +
}
 +
void loop() {
 +
  PORTB = PORTB ^ bit(5);  //Invertir estado del pin digital 13 (bit 5), no altera el resto.
 +
  delay(500);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
== Vea también ==
 
== Vea también ==
* [[bitClear()]]
+
<categorytree mode=all>Funciones bit y byte</categorytree>
* [[bitRead()]]
+
 
* [[bitSet()]]
+
<categorytree mode=all>Operador bit a bit</categorytree>
* [[bitWrite()]]
 
* [[highByte()]]
 
* [[lowByte()]]
 
* [[shiftIn()]]
 
* [[shiftOut()]]
 
* [[not bit a bit]] - (<nowiki>~</nowiki>)
 
* [[and bit a bit]] - (<nowiki>&</nowiki>)
 
* [[or bit a bit]] - (<nowiki>|</nowiki>)
 
* [[xor bit a bit]] - (<nowiki>^</nowiki>)
 
* [[bitshift left]] - (<nowiki><<</nowiki>)
 
* [[or bit a bit compuesto]] <nowiki>(|=)</nowiki>
 
* [[and bit a bit compuesto]] <nowiki>(&=)</nowiki>
 
* [[EEPROM]]
 
  
 
== Referencias externas ==
 
== Referencias externas ==

Revisión actual del 18:29 17 jul 2019

Descripción

Calcula el valor del bit especificado por el parámetro.

bit 0 1 2 3 4 5 6 7
valor 1 2 4 8 16 32 64 128

Sintaxis

bit(valor);
bit(variable);

Parámetros

valor
valor a evaluar.
variable
variable a evaluar.

Retornos

Retorna el bit 2^valor o 2^variable.

Advertencias

Nada.

Ejemplos 1

bit(2);     //4
bit(5);     //32
bit(8);     //256

Ejemplos 2

void setup(){
   Serial.begin(9600);
   for (byte i=0; i<10; i++){
      Serial.println(bit(i));
   }
}
void loop(){
   //Nada
}

Ejemplo 3

Parpadea el LED a bordo.

void setup() {
   DDRB = DDRB | bit(5);    //Configura el pin digital 13 (bit 5) como OUTPUT, no altera el resto.
}
void loop() {
   PORTB = PORTB ^ bit(5);  //Invertir estado del pin digital 13 (bit 5), no altera el resto.
   delay(500);
}

Vea también



Referencias externas