-
-
Notifications
You must be signed in to change notification settings - Fork 732
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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() | ||||||||||||
{ | ||||||||||||
Serial.begin(9600); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's put this in |
||||||||||||
int x = 6; int n = 1; //setting the value of x and n | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is more beginner friendly. |
||||||||||||
Serial.print(bitRead(x,n)); //reading the bit at position n and printing the value | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Necessary due to moving the code into |
||||||||||||
---- | ||||||||||||
[%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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this information would be better in the Parameters section, using the sample reference page as a model: |
||||||||||||
-- | ||||||||||||
|
||||||||||||
// SEE ALSO SECTION | ||||||||||||
[#see_also] | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arduino's standard code style uses attached braces.