Diferencia entre revisiones de «bit()»

De ArduWiki
Saltar a: navegación, buscar
(Vea también)
(Ejemplo 3)
 
(No se muestran 7 ediciones intermedias del mismo usuario)
Línea 24: Línea 24:
 
Nada.
 
Nada.
  
== Ejemplos ==
+
== Ejemplos 1 ==
 
<syntaxhighlight lang="c++">
 
<syntaxhighlight lang="c++">
 
bit(2);    //4
 
bit(2);    //4
 
bit(5);    //32
 
bit(5);    //32
 
bit(8);    //256
 
bit(8);    //256
 +
</syntaxhighlight>
 +
 +
== Ejemplos 2 ==
 +
<syntaxhighlight lang="c++">
 +
void setup(){
 +
  Serial.begin(9600);
 +
  for (byte i=0; i<10; i++){
 +
      Serial.println(bit(i));
 +
  }
 +
}
 +
void loop(){
 +
  //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 ==
+
== Referencias externas ==
 
* [https://www.arduino.cc/reference/es/language/functions/time/millis/ Guia de referencia de Arduino]
 
* [https://www.arduino.cc/reference/es/language/functions/time/millis/ Guia de referencia de Arduino]
  
[[Category:Funciones]]
+
[[Category:Funciones bit y byte]]

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