Skip to content

Commit 180bbca

Browse files
authored
Merge PR #570 "Add example code for bitWrite" from per1234
Add example code for bitWrite
2 parents 93fdf9b + 70ad13f commit 180bbca

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Language/Functions/Bits and Bytes/bitWrite.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ Nothing
4242
// OVERVIEW SECTION ENDS
4343

4444

45+
// HOW TO USE SECTION STARTS
46+
[#howtouse]
47+
--
48+
49+
[float]
50+
=== Example Code
51+
Demonstrates the use of bitWrite by printing the value of a variable to the Serial Monitor before and after the use of `bitWrite()`.
52+
53+
54+
[source,arduino]
55+
void setup() {
56+
Serial.begin(9600);
57+
while (!Serial) {} // wait for serial port to connect. Needed for native USB port only
58+
byte x = 0b10000000; // the 0b prefix indicates a binary constant
59+
Serial.println(x, BIN); // 10000000
60+
bitWrite(x, 0, 1); // write 1 to the least significant bit of x
61+
Serial.println(x, BIN); // 10000001
62+
}
63+
64+
void loop() {}
65+
----
66+
[%hardbreaks]
67+
--
68+
// HOW TO USE SECTION ENDS
69+
70+
4571
// SEE ALSO SECTION
4672
[#see_also]
4773
--

0 commit comments

Comments
 (0)