-
-
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 an example and Notes and warnings #749
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,7 +17,7 @@ subCategories: [ "Bits and Bytes" ] | |||||||||||||||||||||
|
||||||||||||||||||||||
[float] | ||||||||||||||||||||||
=== Description | ||||||||||||||||||||||
Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.). | ||||||||||||||||||||||
Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc). The value returned is 2^n where n is an integer input. | ||||||||||||||||||||||
[%hardbreaks] | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -44,6 +44,32 @@ The value of the bit. | |||||||||||||||||||||
-- | ||||||||||||||||||||||
|
||||||||||||||||||||||
[float] | ||||||||||||||||||||||
=== Example Code | ||||||||||||||||||||||
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄ | ||||||||||||||||||||||
Prints the output of `bit(n)` for n=0 to n=10 to the serial monitor. Values returned are 1 2 4 8 16 till 1024. | ||||||||||||||||||||||
[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
Correctly format code |
||||||||||||||||||||||
} | ||||||||||||||||||||||
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 ensure those using a board like the Leonardo will see all the sketch output from n=0. |
||||||||||||||||||||||
|
||||||||||||||||||||||
void loop() { | ||||||||||||||||||||||
for(int n=0;n<=10;n++) //loop from n=0 till 10 | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
Serial.print(" "); //space between numbers, for readability | ||||||||||||||||||||||
Serial.print(bit(n)); //print the value of bit(n) | ||||||||||||||||||||||
delay(1000); | ||||||||||||||||||||||
Comment on lines
+57
to
+61
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
Use the standard Arduino code formatting style, as implemented by the default configuration of the Arduino IDE "Auto Format" feature. |
||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
---- | ||||||||||||||||||||||
[%hardbreaks] | ||||||||||||||||||||||
|
||||||||||||||||||||||
[float] | ||||||||||||||||||||||
=== Notes and Warnings | ||||||||||||||||||||||
The variable `n` must be an integer type. float and double will return an error and the program will not compile. | ||||||||||||||||||||||
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. It seems better to specify the parameter type in the "Parameters" section of the reference page. I'm not sure what the best approach is for defining types of parameters of macros such as https://github.com/arduino/ArduinoCore-API/blob/1.3.1/api/Common.h#L71 |
||||||||||||||||||||||
|
||||||||||||||||||||||
The maximum value that can be returned by `bit(n)` is 2^31 = 2147483648 after which 0 is returned. | ||||||||||||||||||||||
-- | ||||||||||||||||||||||
=== 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.
Use correct capitalization for Arduino's "Serial Monitor" tool