Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example code/Notes and warnings #751

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Language/Functions/Bits and Bytes/bitRead.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,31 @@ The value of the bit (0 or 1).

--
// OVERVIEW SECTION ENDS
=== Example Code
// Describe what the example code is all about and add relevant code
Reads the bit at the specified position and returns the value. In this example the binary representation of 6 is 0110, since `n=1` the value of the second bit from the right (which is 1 in this case) will be read and printed.
[source,arduino]
----
void setup()
{
Comment on lines +46 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void setup()
{
void setup() {

Arduino's standard code style uses attached braces.

Serial.begin(9600);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()
{
Comment on lines +49 to +52
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
void loop()
{

Let's put this in setup() so it only runs once.

int x = 6; int n = 1; //setting the value of x and n
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int x = 6; int n = 1; //setting the value of x and n
int x = 6;
int n = 1;

This is more beginner friendly.

Serial.print(bitRead(x,n)); //reading the bit at position n and printing the value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}
void loop() {
}

Necessary due to moving the code into setup().

----
[%hardbreaks]

[float]
=== Notes and Warnings
The indexing of the rightmost bit starts from 0, so `n=1` reads the second bit from the right.

Both `x` and `n` must be integer type.

Comment on lines +63 to +64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

--

// SEE ALSO SECTION
[#see_also]
Expand Down