Added example code/Notes and warnings#751
Conversation
Code was tested on Arduino Mega 2560
| void setup() | ||
| { |
There was a problem hiding this comment.
| void setup() | |
| { | |
| void setup() { |
Arduino's standard code style uses attached braces.
| ---- | ||
| void setup() | ||
| { | ||
| Serial.begin(9600); |
There was a problem hiding this comment.
| Serial.begin(9600); | |
| Serial.begin(9600); | |
| while (!Serial) { | |
| ; // wait for serial port to connect. Needed for native USB port only | |
| } |
This will make the example more friendly to users of the native USB boards (e.g., Leonardo).
| } | ||
|
|
||
| void loop() | ||
| { |
There was a problem hiding this comment.
| } | |
| void loop() | |
| { |
Let's put this in setup() so it only runs once.
|
|
||
| void loop() | ||
| { | ||
| int x = 6; int n = 1; //setting the value of x and n |
There was a problem hiding this comment.
| int x = 6; int n = 1; //setting the value of x and n | |
| int x = 6; | |
| int n = 1; |
This is more beginner friendly.
| void loop() | ||
| { | ||
| int x = 6; int n = 1; //setting the value of x and n | ||
| Serial.print(bitRead(x,n)); //reading the bit at position n and printing the value |
There was a problem hiding this comment.
| Serial.print(bitRead(x,n)); //reading the bit at position n and printing the value | |
| Serial.print(bitRead(x, n)); //read the bit at position n and print the value |
- Arduino style code formatting.
- Improve comment wording.
| { | ||
| int x = 6; int n = 1; //setting the value of x and n | ||
| Serial.print(bitRead(x,n)); //reading the bit at position n and printing the value | ||
| } |
There was a problem hiding this comment.
| } | |
| } | |
| void loop() { | |
| } |
Necessary due to moving the code into setup().
| Both `x` and `n` must be integer type. | ||
|
|
There was a problem hiding this comment.
| Both `x` and `n` must be integer type. |
I think this information would be better in the Parameters section, using the sample reference page as a model:
https://github.com/arduino/reference-en/blob/master/AsciiDoc_sample/Reference_Terms/AsciiDoc_Template-Single_Entity.adoc#parameters
|
|
Code was tested on Arduino Mega 2560