From 639da94e542285f46480ab46bdb6641835a4a91f Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 3 Oct 2022 00:38:17 -0700 Subject: [PATCH 1/8] Break code formatting command into multiple lines A script included in the repository formats the code in the examples according to Arduino's standard style. Since the formatter tool does not have a recursive capability, `find` must be used. This results in a fairly long and complex command. Adding line breaks to split the command into its individual arguments, with indentation to indicate the structure of these arguments makes the command easier to understand. --- examples_formatter.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples_formatter.sh b/examples_formatter.sh index b331e55..b13e80d 100755 --- a/examples_formatter.sh +++ b/examples_formatter.sh @@ -1,2 +1,10 @@ # you need to have astyle installed before running this -find examples -regextype posix-extended -regex '.*\.((ino)|(h)|(cpp)|(c))$' -and -type f -exec astyle --options=examples_formatter.conf {} \; +find \ + examples \ + -regextype posix-extended \ + -regex '.*\.((ino)|(h)|(cpp)|(c))$' -and \ + -type f \ + -exec \ + astyle \ + --options=examples_formatter.conf \ + {} \; From 8e1ec355e4bc9558997e0edc4f94ca9c9ef1c8e6 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 3 Oct 2022 01:03:26 -0700 Subject: [PATCH 2/8] Use globbing for extension mapping in formatting script The repository includes a script that formats the example sketch code. This uses a `find` command to recurse through the example folders and run the formatter on each file with a relevant extension. Previously a regular expression was used for that matching. Although perfectly functional, the same can be achieved in an easier to understand and maintain manner using globs. --- examples_formatter.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples_formatter.sh b/examples_formatter.sh index b13e80d..3962693 100755 --- a/examples_formatter.sh +++ b/examples_formatter.sh @@ -1,8 +1,12 @@ # you need to have astyle installed before running this find \ examples \ - -regextype posix-extended \ - -regex '.*\.((ino)|(h)|(cpp)|(c))$' -and \ + \( \ + -name '*.c' -or \ + -name '*.cpp' -or \ + -name '*.h' -or \ + -name '*.ino' \ + \) \ -type f \ -exec \ astyle \ From dac0093581e24a5922f213c61b16b90dbf9c5d2b Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 3 Oct 2022 01:10:59 -0700 Subject: [PATCH 3/8] Add additional supported file extensions to formatter script The `.ipp` and `.tpp` file extensions, commonly used for inline or template function definitions included in C++ header files, have now been added to the Arduino sketch specification as supported extensions. Even though it is unlikely such extensions will ever be used in the example sketches of this repository, it is best to be comprehensive in the extensions covered by the formatter script --- examples_formatter.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples_formatter.sh b/examples_formatter.sh index 3962693..9be18d6 100755 --- a/examples_formatter.sh +++ b/examples_formatter.sh @@ -5,7 +5,9 @@ find \ -name '*.c' -or \ -name '*.cpp' -or \ -name '*.h' -or \ - -name '*.ino' \ + -name '*.ino' -or \ + -name '*.ipp' -or \ + -name '*.tpp' \ \) \ -type f \ -exec \ From 124bead96f027141dc6a88991ed5cc139e08a1dd Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 3 Oct 2022 01:24:57 -0700 Subject: [PATCH 4/8] Make formatter script check availability of tool The repository includes a script that formats the code in the examples. When running this script locally, the contributor must have the formatter tool installed and in the system PATH. Previously this dependency was only explained by a comment in the script, which is not likely to be seen by the contributor in advance of running it. This means they would encounter a somewhat cryptic error message. A more contributor friendly approach is for the script to check for the availability of the tool, then exit with a friendly error message if it is not found. --- examples_formatter.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples_formatter.sh b/examples_formatter.sh index 9be18d6..475c2a4 100755 --- a/examples_formatter.sh +++ b/examples_formatter.sh @@ -1,4 +1,8 @@ -# you need to have astyle installed before running this +if ! which astyle &>/dev/null; then + echo "astyle not found or not in PATH. Please install: https://astyle.sourceforge.net/install.html" + exit 1 +fi + find \ examples \ \( \ From 6b637006f4b531733a15ee79fe6fbaa665bb1566 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 3 Oct 2022 03:38:18 -0700 Subject: [PATCH 5/8] Use formatter script in CI workflow The repository includes a script that formats the code in the example sketches. Previously, this script was only provided to make it easy for contributors to achieve compliant code formatting while preparing a pull request. In addition to this effort to facilitate compliance, enforcement is implemented by a GitHub Actions workflow. Since the formatter tool does not have the directory tree recursion capability needed to process all the files in the repository, it is necessary to implement such capability using a `find` command. Previously this was done both in the script and the workflow. `find` is ridiculously complex and unintuitive, prone to confusing bugs. For this reason, it will be best to avoid maintaining redundant code for recursing through the example code files. This is accomplished by simply running the script from the workflow. Even though the two have different goals (making formatting compliant vs checking whether formatting is compliant), the two are easily aligned by formatting the files in the workflow, then checking for a diff. This approach has been widely used in other Arduino Tooling Team formatting check workflows and I find the diff is very effective at communicating which changes are required, likely more so than the approach previously used in the workflow. --- .github/workflows/code-formatting-check.yml | 29 ++++++++------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/code-formatting-check.yml b/.github/workflows/code-formatting-check.yml index 351099b..9935758 100644 --- a/.github/workflows/code-formatting-check.yml +++ b/.github/workflows/code-formatting-check.yml @@ -4,10 +4,12 @@ on: pull_request: paths: - ".github/workflows/code-formatting-check.yml" + - "examples_formatter.sh" - "examples/**" push: paths: - ".github/workflows/code-formatting-check.yml" + - "examples_formatter.sh" - "examples/**" jobs: @@ -37,27 +39,18 @@ jobs: tar --extract --file="astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz" cd "astyle/build/gcc" make + # Add installation to PATH: + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path + echo "${{ runner.temp }}/astyle/astyle/build/gcc/bin" >> "$GITHUB_PATH" - # GITHUB_WORKSPACE - - name: Check code formatting + - name: Format examples + run: ./examples_formatter.sh + + - name: Check formatting run: | - # Check code formatting of example sketches - # Don't exit on first formatting check fail - set +e - # Set default exit status - EXIT_STATUS=0 - while read -r filePath; do - # Check if it's a file (find matches on pruned folders) - if [[ -f "$filePath" ]]; then - if ! diff --strip-trailing-cr "$filePath" <("${{ runner.temp }}/astyle/astyle/build/gcc/bin/astyle" --options="${GITHUB_WORKSPACE}/examples_formatter.conf" --dry-run <"$filePath"); then - echo "ERROR: Non-compliant code formatting in $filePath" - EXIT_STATUS=1 - fi - fi - done <<<"$(find "${GITHUB_WORKSPACE}/examples" -regextype posix-extended \( -regex '.*\.((ino)|(h)|(cpp)|(c))$' -and -type f \))" - if [[ "$EXIT_STATUS" != "0" ]]; then + if ! git diff --color --exit-code; then echo "Please do an Auto Format on the sketches:" echo "Arduino IDE: Tools > Auto Format" echo "Arduino Web Editor: Ctrl + B" + exit 1 fi - exit "$EXIT_STATUS" From 948bcf861bad9298be43c1ea4583609ceee79d6f Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 3 Oct 2022 04:34:54 -0700 Subject: [PATCH 6/8] Trigger formatting check workflow on changes to formatter configuration For the sake of efficiency, the repository's GitHub Actions workflows are configured to only run when relevant files are modified. The formatter configuration file is one such file, yet was previously omitted from the paths filter. --- .github/workflows/code-formatting-check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/code-formatting-check.yml b/.github/workflows/code-formatting-check.yml index 9935758..76781b9 100644 --- a/.github/workflows/code-formatting-check.yml +++ b/.github/workflows/code-formatting-check.yml @@ -4,11 +4,13 @@ on: pull_request: paths: - ".github/workflows/code-formatting-check.yml" + - "examples_formatter.conf" - "examples_formatter.sh" - "examples/**" push: paths: - ".github/workflows/code-formatting-check.yml" + - "examples_formatter.conf" - "examples_formatter.sh" - "examples/**" From f10994278c11fd3c2c138d0455a898d317907c38 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 3 Oct 2022 04:47:47 -0700 Subject: [PATCH 7/8] Update download URL for Artistic Style in formatting check workflow --- .github/workflows/code-formatting-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-formatting-check.yml b/.github/workflows/code-formatting-check.yml index 76781b9..98a09e2 100644 --- a/.github/workflows/code-formatting-check.yml +++ b/.github/workflows/code-formatting-check.yml @@ -30,7 +30,7 @@ jobs: - name: Download Artistic Style uses: carlosperate/download-file-action@v1 with: - file-url: https://iweb.dl.sourceforge.net/project/astyle/astyle/astyle%20${{ env.ASTYLE_VERSION }}/astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz + file-url: https://cfhcable.dl.sourceforge.net/project/astyle/astyle/astyle%20${{ env.ASTYLE_VERSION }}/astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz location: ${{ runner.temp }}/astyle # See: http://astyle.sourceforge.net/install.html#_GCC_Makefile From 4bbbf5c13a3c40e4435c9e659247e5fcbad2c3e6 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 3 Oct 2022 05:19:15 -0700 Subject: [PATCH 8/8] Use ClangFormat as code formatter for examples The code formatting tool used by the Arduino IDE 1.x "Auto Format" feature is "Artistic Style". This was changed to ClangFormat in Arduino IDE 2.x. Now that the stable Arduino IDE 2.0.0 release has been made, this is now the official code formatting tool for use with Arduino sketches. Due to differences in the two tools, some unavoidable minor changes occurred in the formatting style. This meant that the Arduino IDE 2.x user may experience some unexpected changes to the unmodified official example sketches when running an "Auto Format". So the examples in this repository must be formatted to comply with the updated Arduino code style. The changes are mostly the result of ClangFormat being more "opinionated" than "Artistic Style" was under the fairly light-handed formatter configuration used by Arduino IDE 1.x Auto Format. Due to this factor, formatting changes required to bring the examples into compliance with the new style mostly do not conflict with the Arduino IDE 1.x style. The only exception is the more complex code of the ArduinoISP sketch. In this case, the sketch is more of a utility program than an example, so the formatting changes will not be impactful for users who continue to use the outdated Arduino IDE version. --- .clang-format | 190 +++++++++++++ .github/workflows/code-formatting-check.yml | 37 +-- .../AnalogReadSerial/AnalogReadSerial.ino | 2 +- .../01.Basics/BareMinimum/BareMinimum.ino | 2 - examples/01.Basics/Blink/Blink.ino | 8 +- .../DigitalReadSerial/DigitalReadSerial.ino | 2 +- examples/01.Basics/Fade/Fade.ino | 6 +- .../BlinkWithoutDelay/BlinkWithoutDelay.ino | 8 +- examples/02.Digital/Button/Button.ino | 6 +- examples/02.Digital/Debounce/Debounce.ino | 10 +- .../DigitalInputPullup/DigitalInputPullup.ino | 1 - .../StateChangeDetection.ino | 11 +- examples/02.Digital/toneKeyboard/pitches.h | 106 ++++---- .../02.Digital/toneKeyboard/toneKeyboard.ino | 3 +- examples/02.Digital/toneMelody/pitches.h | 106 ++++---- .../02.Digital/toneMultiple/toneMultiple.ino | 1 - .../tonePitchFollower/tonePitchFollower.ino | 2 +- .../AnalogInOutSerial/AnalogInOutSerial.ino | 6 +- .../03.Analog/AnalogInput/AnalogInput.ino | 2 +- .../03.Analog/Calibration/Calibration.ino | 10 +- examples/03.Analog/Fading/Fading.ino | 6 +- examples/03.Analog/Smoothing/Smoothing.ino | 10 +- .../ASCIITable/ASCIITable.ino | 4 +- examples/04.Communication/Dimmer/Dimmer.ino | 2 +- examples/04.Communication/Midi/Midi.ino | 2 +- .../PhysicalPixel/PhysicalPixel.ino | 4 +- .../ReadASCIIString/ReadASCIIString.ino | 1 - .../SerialCallResponse/SerialCallResponse.ino | 12 +- .../SerialCallResponseASCII.ino | 12 +- .../SerialEvent/SerialEvent.ino | 2 +- .../SerialPassthrough/SerialPassthrough.ino | 8 +- .../VirtualColorMixer/VirtualColorMixer.ino | 6 +- examples/05.Control/Arrays/Arrays.ino | 7 +- .../ForLoopIteration/ForLoopIteration.ino | 2 +- .../IfStatementConditional.ino | 8 +- .../WhileStatementConditional.ino | 10 +- examples/05.Control/switchCase/switchCase.ino | 14 +- examples/06.Sensors/ADXL3xx/ADXL3xx.ino | 10 +- examples/06.Sensors/Knock/Knock.ino | 12 +- examples/06.Sensors/Memsic2125/Memsic2125.ino | 4 +- .../RowColumnScanning/RowColumnScanning.ino | 1 - examples/07.Display/barGraph/barGraph.ino | 6 +- .../CharacterAnalysis/CharacterAnalysis.ino | 2 +- .../StringAdditionOperator.ino | 27 +- .../StringAppendOperator.ino | 15 +- .../StringCaseChanges/StringCaseChanges.ino | 5 +- .../StringCharacters/StringCharacters.ino | 5 +- .../StringComparisonOperators.ino | 4 +- .../StringConstructors/StringConstructors.ino | 30 +-- .../StringIndexOf/StringIndexOf.ino | 7 +- .../08.Strings/StringLength/StringLength.ino | 6 +- .../StringLengthTrim/StringLengthTrim.ino | 5 +- .../StringReplace/StringReplace.ino | 5 +- .../StringStartsWithEndsWith.ino | 5 +- .../StringSubstring/StringSubstring.ino | 5 +- .../08.Strings/StringToInt/StringToInt.ino | 4 +- .../KeyboardLogout/KeyboardLogout.ino | 3 +- .../KeyboardMessage/KeyboardMessage.ino | 6 +- .../KeyboardReprogram/KeyboardReprogram.ino | 3 +- .../KeyboardAndMouseControl.ino | 3 +- .../ButtonMouseControl/ButtonMouseControl.ino | 8 +- .../JoystickMouseControl.ino | 26 +- .../p02_SpaceshipInterface.ino | 16 +- .../p03_LoveOMeter/p03_LoveOMeter.ino | 6 +- .../p04_ColorMixingLamp.ino | 22 +- .../p05_ServoMoodIndicator.ino | 12 +- .../p07_Keyboard/p07_Keyboard.ino | 2 +- .../p08_DigitalHourglass.ino | 10 +- .../p09_MotorizedPinwheel.ino | 4 +- .../p10_Zoetrope/p10_Zoetrope.ino | 26 +- .../p12_KnockLock/p12_KnockLock.ino | 10 +- .../p15_HackingButtons/p15_HackingButtons.ino | 4 +- .../11.ArduinoISP/ArduinoISP/ArduinoISP.ino | 254 +++++++++--------- examples_formatter.conf | 45 ---- examples_formatter.sh | 10 +- 75 files changed, 701 insertions(+), 556 deletions(-) create mode 100644 .clang-format delete mode 100644 examples_formatter.conf diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..e608f4e --- /dev/null +++ b/.clang-format @@ -0,0 +1,190 @@ +# Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration +--- +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None +AlignEscapedNewlines: DontAlign +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLambdasOnASingleLine: Empty +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: No +AttributeMacros: + - __capability +BasedOnStyle: LLVM +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAfterJavaFieldAnnotations: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Attach +BreakBeforeConceptDeclarations: false +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakConstructorInitializersBeforeComma: false +BreakInheritanceList: BeforeColon +BreakStringLiterals: false +ColumnLimit: 0 +CommentPragmas: '' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +EmptyLineAfterAccessModifier: Leave +EmptyLineBeforeAccessModifier: Leave +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: true +IndentCaseLabels: true +IndentExternBlock: Indent +IndentGotoLabels: false +IndentPPDirectives: None +IndentRequires: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +Language: Cpp +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 100000 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PPIndentWidth: -1 +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 1 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 1 +PenaltyBreakFirstLessLess: 1 +PenaltyBreakOpenParenthesis: 1 +PenaltyBreakString: 1 +PenaltyBreakTemplateDeclaration: 1 +PenaltyExcessCharacter: 1 +PenaltyIndentedWhitespace: 1 +PenaltyReturnTypeOnItsOwnLine: 1 +PointerAlignment: Right +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: false +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 0 +SortIncludes: Never +SortJavaStaticImport: Before +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Leave +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInLineCommentPrefix: + Minimum: 0 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 2 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME diff --git a/.github/workflows/code-formatting-check.yml b/.github/workflows/code-formatting-check.yml index 98a09e2..5406dae 100644 --- a/.github/workflows/code-formatting-check.yml +++ b/.github/workflows/code-formatting-check.yml @@ -4,13 +4,13 @@ on: pull_request: paths: - ".github/workflows/code-formatting-check.yml" - - "examples_formatter.conf" + - ".clang-format" - "examples_formatter.sh" - "examples/**" push: paths: - ".github/workflows/code-formatting-check.yml" - - "examples_formatter.conf" + - ".clang-format" - "examples_formatter.sh" - "examples/**" @@ -19,31 +19,34 @@ jobs: runs-on: ubuntu-latest env: - # See: https://sourceforge.net/projects/astyle/files/astyle/ - ASTYLE_VERSION: 3.1 + # See: https://github.com/arduino/arduino-ide/blob/main/arduino-ide-extension/package.json + CLANG_FORMAT_VERSION: 14.0.0 steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable + echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV" + - name: Checkout uses: actions/checkout@v3 - # See: http://astyle.sourceforge.net/ - - name: Download Artistic Style - uses: carlosperate/download-file-action@v1 + - name: Download ClangFormat + id: download + uses: MrOctopus/download-asset-action@1.0 with: - file-url: https://cfhcable.dl.sourceforge.net/project/astyle/astyle/astyle%20${{ env.ASTYLE_VERSION }}/astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz - location: ${{ runner.temp }}/astyle + repository: arduino/clang-static-binaries + tag: ${{ env.CLANG_FORMAT_VERSION }} + asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2 + target: ${{ env.CLANG_FORMAT_INSTALL_PATH }} - # See: http://astyle.sourceforge.net/install.html#_GCC_Makefile - - name: Build Artistic Style + - name: Install ClangFormat run: | - # Build Artistic Style - cd "${{ runner.temp }}/astyle" - tar --extract --file="astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz" - cd "astyle/build/gcc" - make + cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}" + tar --extract --file="${{ steps.download.outputs.name }}" # Add installation to PATH: # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path - echo "${{ runner.temp }}/astyle/astyle/build/gcc/bin" >> "$GITHUB_PATH" + echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH" - name: Format examples run: ./examples_formatter.sh diff --git a/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino b/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino index 10e67ec..d1dd321 100644 --- a/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino +++ b/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino @@ -22,5 +22,5 @@ void loop() { int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); - delay(1); // delay in between reads for stability + delay(1); // delay in between reads for stability } diff --git a/examples/01.Basics/BareMinimum/BareMinimum.ino b/examples/01.Basics/BareMinimum/BareMinimum.ino index 95c2b6e..ab62321 100644 --- a/examples/01.Basics/BareMinimum/BareMinimum.ino +++ b/examples/01.Basics/BareMinimum/BareMinimum.ino @@ -1,9 +1,7 @@ void setup() { // put your setup code here, to run once: - } void loop() { // put your main code here, to run repeatedly: - } diff --git a/examples/01.Basics/Blink/Blink.ino b/examples/01.Basics/Blink/Blink.ino index 9abb8f5..9f8b472 100644 --- a/examples/01.Basics/Blink/Blink.ino +++ b/examples/01.Basics/Blink/Blink.ino @@ -30,8 +30,8 @@ void setup() { // the loop function runs over and over again forever void loop() { - digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) - delay(1000); // wait for a second - digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW - delay(1000); // wait for a second + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second } diff --git a/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino b/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino index 49389fe..3456f2f 100644 --- a/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino +++ b/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino @@ -25,5 +25,5 @@ void loop() { int buttonState = digitalRead(pushButton); // print out the state of the button: Serial.println(buttonState); - delay(1); // delay in between reads for stability + delay(1); // delay in between reads for stability } diff --git a/examples/01.Basics/Fade/Fade.ino b/examples/01.Basics/Fade/Fade.ino index e598b03..4637979 100644 --- a/examples/01.Basics/Fade/Fade.ino +++ b/examples/01.Basics/Fade/Fade.ino @@ -13,9 +13,9 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade */ -int led = 9; // the PWM pin the LED is attached to -int brightness = 0; // how bright the LED is -int fadeAmount = 5; // how many points to fade the LED by +int led = 9; // the PWM pin the LED is attached to +int brightness = 0; // how bright the LED is +int fadeAmount = 5; // how many points to fade the LED by // the setup routine runs once when you press reset: void setup() { diff --git a/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino b/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino index ac47087..d266349 100644 --- a/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino +++ b/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @@ -29,17 +29,17 @@ */ // constants won't change. Used here to set a pin number: -const int ledPin = LED_BUILTIN;// the number of the LED pin +const int ledPin = LED_BUILTIN; // the number of the LED pin // Variables will change: -int ledState = LOW; // ledState used to set the LED +int ledState = LOW; // ledState used to set the LED // Generally, you should use "unsigned long" for variables that hold time // The value will quickly become too large for an int to store -unsigned long previousMillis = 0; // will store last time LED was updated +unsigned long previousMillis = 0; // will store last time LED was updated // constants won't change: -const long interval = 1000; // interval at which to blink (milliseconds) +const long interval = 1000; // interval at which to blink (milliseconds) void setup() { // set the digital pin as output: diff --git a/examples/02.Digital/Button/Button.ino b/examples/02.Digital/Button/Button.ino index 7732bc8..e041c31 100644 --- a/examples/02.Digital/Button/Button.ino +++ b/examples/02.Digital/Button/Button.ino @@ -23,11 +23,11 @@ */ // constants won't change. They're used here to set pin numbers: -const int buttonPin = 2; // the number of the pushbutton pin -const int ledPin = 13; // the number of the LED pin +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin // variables will change: -int buttonState = 0; // variable for reading the pushbutton status +int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: diff --git a/examples/02.Digital/Debounce/Debounce.ino b/examples/02.Digital/Debounce/Debounce.ino index 42cd1dc..6460d90 100644 --- a/examples/02.Digital/Debounce/Debounce.ino +++ b/examples/02.Digital/Debounce/Debounce.ino @@ -28,13 +28,13 @@ */ // constants won't change. They're used here to set pin numbers: -const int buttonPin = 2; // the number of the pushbutton pin -const int ledPin = 13; // the number of the LED pin +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin // Variables will change: -int ledState = HIGH; // the current state of the output pin -int buttonState; // the current reading from the input pin -int lastButtonState = LOW; // the previous reading from the input pin +int ledState = HIGH; // the current state of the output pin +int buttonState; // the current reading from the input pin +int lastButtonState = LOW; // the previous reading from the input pin // the following variables are unsigned longs because the time, measured in // milliseconds, will quickly become a bigger number than can be stored in an int. diff --git a/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino b/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino index 16863a0..0f0eea1 100644 --- a/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino +++ b/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino @@ -26,7 +26,6 @@ void setup() { //configure pin 2 as an input and enable the internal pull-up resistor pinMode(2, INPUT_PULLUP); pinMode(13, OUTPUT); - } void loop() { diff --git a/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino b/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino index d3b2122..5205e17 100644 --- a/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino +++ b/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino @@ -25,13 +25,13 @@ */ // this constant won't change: -const int buttonPin = 2; // the pin that the pushbutton is attached to -const int ledPin = 13; // the pin that the LED is attached to +const int buttonPin = 2; // the pin that the pushbutton is attached to +const int ledPin = 13; // the pin that the LED is attached to // Variables will change: -int buttonPushCounter = 0; // counter for the number of button presses -int buttonState = 0; // current state of the button -int lastButtonState = 0; // previous state of the button +int buttonPushCounter = 0; // counter for the number of button presses +int buttonState = 0; // current state of the button +int lastButtonState = 0; // previous state of the button void setup() { // initialize the button pin as a input: @@ -75,5 +75,4 @@ void loop() { } else { digitalWrite(ledPin, LOW); } - } diff --git a/examples/02.Digital/toneKeyboard/pitches.h b/examples/02.Digital/toneKeyboard/pitches.h index 70b06bc..a0d69ac 100644 --- a/examples/02.Digital/toneKeyboard/pitches.h +++ b/examples/02.Digital/toneKeyboard/pitches.h @@ -2,94 +2,92 @@ Public Constants *************************************************/ -#define NOTE_B0 31 -#define NOTE_C1 33 +#define NOTE_B0 31 +#define NOTE_C1 33 #define NOTE_CS1 35 -#define NOTE_D1 37 +#define NOTE_D1 37 #define NOTE_DS1 39 -#define NOTE_E1 41 -#define NOTE_F1 44 +#define NOTE_E1 41 +#define NOTE_F1 44 #define NOTE_FS1 46 -#define NOTE_G1 49 +#define NOTE_G1 49 #define NOTE_GS1 52 -#define NOTE_A1 55 +#define NOTE_A1 55 #define NOTE_AS1 58 -#define NOTE_B1 62 -#define NOTE_C2 65 +#define NOTE_B1 62 +#define NOTE_C2 65 #define NOTE_CS2 69 -#define NOTE_D2 73 +#define NOTE_D2 73 #define NOTE_DS2 78 -#define NOTE_E2 82 -#define NOTE_F2 87 +#define NOTE_E2 82 +#define NOTE_F2 87 #define NOTE_FS2 93 -#define NOTE_G2 98 +#define NOTE_G2 98 #define NOTE_GS2 104 -#define NOTE_A2 110 +#define NOTE_A2 110 #define NOTE_AS2 117 -#define NOTE_B2 123 -#define NOTE_C3 131 +#define NOTE_B2 123 +#define NOTE_C3 131 #define NOTE_CS3 139 -#define NOTE_D3 147 +#define NOTE_D3 147 #define NOTE_DS3 156 -#define NOTE_E3 165 -#define NOTE_F3 175 +#define NOTE_E3 165 +#define NOTE_F3 175 #define NOTE_FS3 185 -#define NOTE_G3 196 +#define NOTE_G3 196 #define NOTE_GS3 208 -#define NOTE_A3 220 +#define NOTE_A3 220 #define NOTE_AS3 233 -#define NOTE_B3 247 -#define NOTE_C4 262 +#define NOTE_B3 247 +#define NOTE_C4 262 #define NOTE_CS4 277 -#define NOTE_D4 294 +#define NOTE_D4 294 #define NOTE_DS4 311 -#define NOTE_E4 330 -#define NOTE_F4 349 +#define NOTE_E4 330 +#define NOTE_F4 349 #define NOTE_FS4 370 -#define NOTE_G4 392 +#define NOTE_G4 392 #define NOTE_GS4 415 -#define NOTE_A4 440 +#define NOTE_A4 440 #define NOTE_AS4 466 -#define NOTE_B4 494 -#define NOTE_C5 523 +#define NOTE_B4 494 +#define NOTE_C5 523 #define NOTE_CS5 554 -#define NOTE_D5 587 +#define NOTE_D5 587 #define NOTE_DS5 622 -#define NOTE_E5 659 -#define NOTE_F5 698 +#define NOTE_E5 659 +#define NOTE_F5 698 #define NOTE_FS5 740 -#define NOTE_G5 784 +#define NOTE_G5 784 #define NOTE_GS5 831 -#define NOTE_A5 880 +#define NOTE_A5 880 #define NOTE_AS5 932 -#define NOTE_B5 988 -#define NOTE_C6 1047 +#define NOTE_B5 988 +#define NOTE_C6 1047 #define NOTE_CS6 1109 -#define NOTE_D6 1175 +#define NOTE_D6 1175 #define NOTE_DS6 1245 -#define NOTE_E6 1319 -#define NOTE_F6 1397 +#define NOTE_E6 1319 +#define NOTE_F6 1397 #define NOTE_FS6 1480 -#define NOTE_G6 1568 +#define NOTE_G6 1568 #define NOTE_GS6 1661 -#define NOTE_A6 1760 +#define NOTE_A6 1760 #define NOTE_AS6 1865 -#define NOTE_B6 1976 -#define NOTE_C7 2093 +#define NOTE_B6 1976 +#define NOTE_C7 2093 #define NOTE_CS7 2217 -#define NOTE_D7 2349 +#define NOTE_D7 2349 #define NOTE_DS7 2489 -#define NOTE_E7 2637 -#define NOTE_F7 2794 +#define NOTE_E7 2637 +#define NOTE_F7 2794 #define NOTE_FS7 2960 -#define NOTE_G7 3136 +#define NOTE_G7 3136 #define NOTE_GS7 3322 -#define NOTE_A7 3520 +#define NOTE_A7 3520 #define NOTE_AS7 3729 -#define NOTE_B7 3951 -#define NOTE_C8 4186 +#define NOTE_B7 3951 +#define NOTE_C8 4186 #define NOTE_CS8 4435 -#define NOTE_D8 4699 +#define NOTE_D8 4699 #define NOTE_DS8 4978 - - diff --git a/examples/02.Digital/toneKeyboard/toneKeyboard.ino b/examples/02.Digital/toneKeyboard/toneKeyboard.ino index 99e1cc5..c8e73c6 100644 --- a/examples/02.Digital/toneKeyboard/toneKeyboard.ino +++ b/examples/02.Digital/toneKeyboard/toneKeyboard.ino @@ -19,7 +19,7 @@ #include "pitches.h" -const int threshold = 10; // minimum reading of the sensors that generates a note +const int threshold = 10; // minimum reading of the sensors that generates a note // notes to play, corresponding to the 3 sensors: int notes[] = { @@ -27,7 +27,6 @@ int notes[] = { }; void setup() { - } void loop() { diff --git a/examples/02.Digital/toneMelody/pitches.h b/examples/02.Digital/toneMelody/pitches.h index 70b06bc..a0d69ac 100644 --- a/examples/02.Digital/toneMelody/pitches.h +++ b/examples/02.Digital/toneMelody/pitches.h @@ -2,94 +2,92 @@ Public Constants *************************************************/ -#define NOTE_B0 31 -#define NOTE_C1 33 +#define NOTE_B0 31 +#define NOTE_C1 33 #define NOTE_CS1 35 -#define NOTE_D1 37 +#define NOTE_D1 37 #define NOTE_DS1 39 -#define NOTE_E1 41 -#define NOTE_F1 44 +#define NOTE_E1 41 +#define NOTE_F1 44 #define NOTE_FS1 46 -#define NOTE_G1 49 +#define NOTE_G1 49 #define NOTE_GS1 52 -#define NOTE_A1 55 +#define NOTE_A1 55 #define NOTE_AS1 58 -#define NOTE_B1 62 -#define NOTE_C2 65 +#define NOTE_B1 62 +#define NOTE_C2 65 #define NOTE_CS2 69 -#define NOTE_D2 73 +#define NOTE_D2 73 #define NOTE_DS2 78 -#define NOTE_E2 82 -#define NOTE_F2 87 +#define NOTE_E2 82 +#define NOTE_F2 87 #define NOTE_FS2 93 -#define NOTE_G2 98 +#define NOTE_G2 98 #define NOTE_GS2 104 -#define NOTE_A2 110 +#define NOTE_A2 110 #define NOTE_AS2 117 -#define NOTE_B2 123 -#define NOTE_C3 131 +#define NOTE_B2 123 +#define NOTE_C3 131 #define NOTE_CS3 139 -#define NOTE_D3 147 +#define NOTE_D3 147 #define NOTE_DS3 156 -#define NOTE_E3 165 -#define NOTE_F3 175 +#define NOTE_E3 165 +#define NOTE_F3 175 #define NOTE_FS3 185 -#define NOTE_G3 196 +#define NOTE_G3 196 #define NOTE_GS3 208 -#define NOTE_A3 220 +#define NOTE_A3 220 #define NOTE_AS3 233 -#define NOTE_B3 247 -#define NOTE_C4 262 +#define NOTE_B3 247 +#define NOTE_C4 262 #define NOTE_CS4 277 -#define NOTE_D4 294 +#define NOTE_D4 294 #define NOTE_DS4 311 -#define NOTE_E4 330 -#define NOTE_F4 349 +#define NOTE_E4 330 +#define NOTE_F4 349 #define NOTE_FS4 370 -#define NOTE_G4 392 +#define NOTE_G4 392 #define NOTE_GS4 415 -#define NOTE_A4 440 +#define NOTE_A4 440 #define NOTE_AS4 466 -#define NOTE_B4 494 -#define NOTE_C5 523 +#define NOTE_B4 494 +#define NOTE_C5 523 #define NOTE_CS5 554 -#define NOTE_D5 587 +#define NOTE_D5 587 #define NOTE_DS5 622 -#define NOTE_E5 659 -#define NOTE_F5 698 +#define NOTE_E5 659 +#define NOTE_F5 698 #define NOTE_FS5 740 -#define NOTE_G5 784 +#define NOTE_G5 784 #define NOTE_GS5 831 -#define NOTE_A5 880 +#define NOTE_A5 880 #define NOTE_AS5 932 -#define NOTE_B5 988 -#define NOTE_C6 1047 +#define NOTE_B5 988 +#define NOTE_C6 1047 #define NOTE_CS6 1109 -#define NOTE_D6 1175 +#define NOTE_D6 1175 #define NOTE_DS6 1245 -#define NOTE_E6 1319 -#define NOTE_F6 1397 +#define NOTE_E6 1319 +#define NOTE_F6 1397 #define NOTE_FS6 1480 -#define NOTE_G6 1568 +#define NOTE_G6 1568 #define NOTE_GS6 1661 -#define NOTE_A6 1760 +#define NOTE_A6 1760 #define NOTE_AS6 1865 -#define NOTE_B6 1976 -#define NOTE_C7 2093 +#define NOTE_B6 1976 +#define NOTE_C7 2093 #define NOTE_CS7 2217 -#define NOTE_D7 2349 +#define NOTE_D7 2349 #define NOTE_DS7 2489 -#define NOTE_E7 2637 -#define NOTE_F7 2794 +#define NOTE_E7 2637 +#define NOTE_F7 2794 #define NOTE_FS7 2960 -#define NOTE_G7 3136 +#define NOTE_G7 3136 #define NOTE_GS7 3322 -#define NOTE_A7 3520 +#define NOTE_A7 3520 #define NOTE_AS7 3729 -#define NOTE_B7 3951 -#define NOTE_C8 4186 +#define NOTE_B7 3951 +#define NOTE_C8 4186 #define NOTE_CS8 4435 -#define NOTE_D8 4699 +#define NOTE_D8 4699 #define NOTE_DS8 4978 - - diff --git a/examples/02.Digital/toneMultiple/toneMultiple.ino b/examples/02.Digital/toneMultiple/toneMultiple.ino index 63a6020..8d97fa7 100644 --- a/examples/02.Digital/toneMultiple/toneMultiple.ino +++ b/examples/02.Digital/toneMultiple/toneMultiple.ino @@ -16,7 +16,6 @@ */ void setup() { - } void loop() { diff --git a/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino b/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino index 3171cfc..592f671 100644 --- a/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino +++ b/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino @@ -35,5 +35,5 @@ void loop() { // play the pitch: tone(9, thisPitch, 10); - delay(1); // delay in between reads for stability + delay(1); // delay in between reads for stability } diff --git a/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino b/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino index 4033ca0..851342d 100644 --- a/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino +++ b/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino @@ -22,10 +22,10 @@ // These constants won't change. They're used to give names to the pins used: const int analogInPin = A0; // Analog input pin that the potentiometer is attached to -const int analogOutPin = 9; // Analog output pin that the LED is attached to +const int analogOutPin = 9; // Analog output pin that the LED is attached to -int sensorValue = 0; // value read from the pot -int outputValue = 0; // value output to the PWM (analog out) +int sensorValue = 0; // value read from the pot +int outputValue = 0; // value output to the PWM (analog out) void setup() { // initialize serial communications at 9600 bps: diff --git a/examples/03.Analog/AnalogInput/AnalogInput.ino b/examples/03.Analog/AnalogInput/AnalogInput.ino index 9a1bbdd..735a8b5 100644 --- a/examples/03.Analog/AnalogInput/AnalogInput.ino +++ b/examples/03.Analog/AnalogInput/AnalogInput.ino @@ -27,7 +27,7 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput */ -int sensorPin = A0; // select the input pin for the potentiometer +int sensorPin = A0; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor diff --git a/examples/03.Analog/Calibration/Calibration.ino b/examples/03.Analog/Calibration/Calibration.ino index ba5cf70..e0f639b 100644 --- a/examples/03.Analog/Calibration/Calibration.ino +++ b/examples/03.Analog/Calibration/Calibration.ino @@ -27,13 +27,13 @@ */ // These constants won't change: -const int sensorPin = A0; // pin that the sensor is attached to -const int ledPin = 9; // pin that the LED is attached to +const int sensorPin = A0; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to // variables: -int sensorValue = 0; // the sensor value -int sensorMin = 1023; // minimum sensor value -int sensorMax = 0; // maximum sensor value +int sensorValue = 0; // the sensor value +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value void setup() { diff --git a/examples/03.Analog/Fading/Fading.ino b/examples/03.Analog/Fading/Fading.ino index da694e5..7923546 100644 --- a/examples/03.Analog/Fading/Fading.ino +++ b/examples/03.Analog/Fading/Fading.ino @@ -16,7 +16,7 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fading */ -int ledPin = 9; // LED connected to digital pin 9 +int ledPin = 9; // LED connected to digital pin 9 void setup() { // nothing happens in setup @@ -24,7 +24,7 @@ void setup() { void loop() { // fade in from min to max in increments of 5 points: - for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { + for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(ledPin, fadeValue); // wait for 30 milliseconds to see the dimming effect @@ -32,7 +32,7 @@ void loop() { } // fade out from max to min in increments of 5 points: - for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { + for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(ledPin, fadeValue); // wait for 30 milliseconds to see the dimming effect diff --git a/examples/03.Analog/Smoothing/Smoothing.ino b/examples/03.Analog/Smoothing/Smoothing.ino index eece339..15c0f1a 100644 --- a/examples/03.Analog/Smoothing/Smoothing.ino +++ b/examples/03.Analog/Smoothing/Smoothing.ino @@ -24,10 +24,10 @@ // value to determine the size of the readings array. const int numReadings = 10; -int readings[numReadings]; // the readings from the analog input -int readIndex = 0; // the index of the current reading -int total = 0; // the running total -int average = 0; // the average +int readings[numReadings]; // the readings from the analog input +int readIndex = 0; // the index of the current reading +int total = 0; // the running total +int average = 0; // the average int inputPin = A0; @@ -60,5 +60,5 @@ void loop() { average = total / numReadings; // send it to the computer as ASCII digits Serial.println(average); - delay(1); // delay in between reads for stability + delay(1); // delay in between reads for stability } diff --git a/examples/04.Communication/ASCIITable/ASCIITable.ino b/examples/04.Communication/ASCIITable/ASCIITable.ino index f3d4bd0..f7fc4d4 100644 --- a/examples/04.Communication/ASCIITable/ASCIITable.ino +++ b/examples/04.Communication/ASCIITable/ASCIITable.ino @@ -23,7 +23,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // prints title with ending line break @@ -66,7 +66,7 @@ void loop() { Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: - if (thisByte == 126) { // you could also use if (thisByte == '~') { + if (thisByte == 126) { // you could also use if (thisByte == '~') { // This loop loops forever and does nothing while (true) { continue; diff --git a/examples/04.Communication/Dimmer/Dimmer.ino b/examples/04.Communication/Dimmer/Dimmer.ino index fc121a0..2f82344 100644 --- a/examples/04.Communication/Dimmer/Dimmer.ino +++ b/examples/04.Communication/Dimmer/Dimmer.ino @@ -20,7 +20,7 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/Dimmer */ -const int ledPin = 9; // the pin that the LED is attached to +const int ledPin = 9; // the pin that the LED is attached to void setup() { // initialize the serial communication: diff --git a/examples/04.Communication/Midi/Midi.ino b/examples/04.Communication/Midi/Midi.ino index 851fa9b..0602bf0 100644 --- a/examples/04.Communication/Midi/Midi.ino +++ b/examples/04.Communication/Midi/Midi.ino @@ -27,7 +27,7 @@ void setup() { void loop() { // play notes from F#-0 (0x1E) to F#-5 (0x5A): - for (int note = 0x1E; note < 0x5A; note ++) { + for (int note = 0x1E; note < 0x5A; note++) { //Note on channel 1 (0x90), some note value (note), middle velocity (0x45): noteOn(0x90, note, 0x45); delay(100); diff --git a/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino b/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino index 1582118..cff02ef 100644 --- a/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino +++ b/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino @@ -21,8 +21,8 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/PhysicalPixel */ -const int ledPin = 13; // the pin that the LED is attached to -int incomingByte; // a variable to read incoming serial data into +const int ledPin = 13; // the pin that the LED is attached to +int incomingByte; // a variable to read incoming serial data into void setup() { // initialize serial communication: diff --git a/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino b/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino index bbd395b..1cab997 100644 --- a/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino +++ b/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino @@ -33,7 +33,6 @@ void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); - } void loop() { diff --git a/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino b/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino index 6fb0a60..b778774 100644 --- a/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino +++ b/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino @@ -21,16 +21,16 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialCallResponse */ -int firstSensor = 0; // first analog sensor -int secondSensor = 0; // second analog sensor -int thirdSensor = 0; // digital sensor -int inByte = 0; // incoming serial byte +int firstSensor = 0; // first analog sensor +int secondSensor = 0; // second analog sensor +int thirdSensor = 0; // digital sensor +int inByte = 0; // incoming serial byte void setup() { // start serial port at 9600 bps: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } pinMode(2, INPUT); // digital sensor is on digital pin 2 @@ -59,7 +59,7 @@ void loop() { void establishContact() { while (Serial.available() <= 0) { - Serial.print('A'); // send a capital A + Serial.print('A'); // send a capital A delay(300); } } diff --git a/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino index 44b2155..e5b02cd 100644 --- a/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino +++ b/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -22,16 +22,16 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialCallResponseASCII */ -int firstSensor = 0; // first analog sensor -int secondSensor = 0; // second analog sensor -int thirdSensor = 0; // digital sensor -int inByte = 0; // incoming serial byte +int firstSensor = 0; // first analog sensor +int secondSensor = 0; // second analog sensor +int thirdSensor = 0; // digital sensor +int inByte = 0; // incoming serial byte void setup() { // start serial port at 9600 bps and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } @@ -61,7 +61,7 @@ void loop() { void establishContact() { while (Serial.available() <= 0) { - Serial.println("0,0,0"); // send an initial string + Serial.println("0,0,0"); // send an initial string delay(300); } } diff --git a/examples/04.Communication/SerialEvent/SerialEvent.ino b/examples/04.Communication/SerialEvent/SerialEvent.ino index 831b98d..13c5630 100644 --- a/examples/04.Communication/SerialEvent/SerialEvent.ino +++ b/examples/04.Communication/SerialEvent/SerialEvent.ino @@ -18,7 +18,7 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialEvent */ -String inputString = ""; // a String to hold incoming data +String inputString = ""; // a String to hold incoming data bool stringComplete = false; // whether the string is complete void setup() { diff --git a/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino b/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino index 84824cf..8f46bbe 100644 --- a/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino +++ b/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino @@ -30,11 +30,11 @@ void setup() { } void loop() { - if (Serial.available()) { // If anything comes in Serial (USB), - Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1) + if (Serial.available()) { // If anything comes in Serial (USB), + Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1) } - if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1) - Serial.write(Serial1.read()); // read it and send it out Serial (USB) + if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1) + Serial.write(Serial1.read()); // read it and send it out Serial (USB) } } diff --git a/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino b/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino index cf66348..6ffd934 100644 --- a/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino +++ b/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino @@ -16,9 +16,9 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/VirtualColorMixer */ -const int redPin = A0; // sensor to control red color -const int greenPin = A1; // sensor to control green color -const int bluePin = A2; // sensor to control blue color +const int redPin = A0; // sensor to control red color +const int greenPin = A1; // sensor to control green color +const int bluePin = A2; // sensor to control blue color void setup() { Serial.begin(9600); diff --git a/examples/05.Control/Arrays/Arrays.ino b/examples/05.Control/Arrays/Arrays.ino index dbbb4b4..75d59ee 100644 --- a/examples/05.Control/Arrays/Arrays.ino +++ b/examples/05.Control/Arrays/Arrays.ino @@ -20,11 +20,11 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/Arrays */ -int timer = 100; // The higher the number, the slower the timing. +int timer = 100; // The higher the number, the slower the timing. int ledPins[] = { 2, 7, 4, 6, 5, 3 -}; // an array of pin numbers to which LEDs are attached -int pinCount = 6; // the number of pins (i.e. the length of the array) +}; // an array of pin numbers to which LEDs are attached +int pinCount = 6; // the number of pins (i.e. the length of the array) void setup() { // the array elements are numbered from 0 to (pinCount - 1). @@ -42,7 +42,6 @@ void loop() { delay(timer); // turn the pin off: digitalWrite(ledPins[thisPin], LOW); - } // loop from the highest pin to the lowest: diff --git a/examples/05.Control/ForLoopIteration/ForLoopIteration.ino b/examples/05.Control/ForLoopIteration/ForLoopIteration.ino index af9cd7d..e6b40e7 100644 --- a/examples/05.Control/ForLoopIteration/ForLoopIteration.ino +++ b/examples/05.Control/ForLoopIteration/ForLoopIteration.ino @@ -17,7 +17,7 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/ForLoopIteration */ -int timer = 100; // The higher the number, the slower the timing. +int timer = 100; // The higher the number, the slower the timing. void setup() { // use a for loop to initialize each pin as an output: diff --git a/examples/05.Control/IfStatementConditional/IfStatementConditional.ino b/examples/05.Control/IfStatementConditional/IfStatementConditional.ino index efd233f..ac6041a 100644 --- a/examples/05.Control/IfStatementConditional/IfStatementConditional.ino +++ b/examples/05.Control/IfStatementConditional/IfStatementConditional.ino @@ -25,9 +25,9 @@ */ // These constants won't change: -const int analogPin = A0; // pin that the sensor is attached to -const int ledPin = 13; // pin that the LED is attached to -const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input +const int analogPin = A0; // pin that the sensor is attached to +const int ledPin = 13; // pin that the LED is attached to +const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input void setup() { // initialize the LED pin as an output: @@ -49,5 +49,5 @@ void loop() { // print the analog value: Serial.println(analogValue); - delay(1); // delay in between reads for stability + delay(1); // delay in between reads for stability } diff --git a/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino b/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino index a0b42e1..0a36341 100644 --- a/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino +++ b/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino @@ -29,16 +29,16 @@ // These constants won't change: -const int sensorPin = A0; // pin that the sensor is attached to -const int ledPin = 9; // pin that the LED is attached to -const int indicatorLedPin = 13; // pin that the built-in LED is attached to -const int buttonPin = 2; // pin that the button is attached to +const int sensorPin = A0; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to +const int indicatorLedPin = 13; // pin that the built-in LED is attached to +const int buttonPin = 2; // pin that the button is attached to // These variables will change: int sensorMin = 1023; // minimum sensor value int sensorMax = 0; // maximum sensor value -int sensorValue = 0; // the sensor value +int sensorValue = 0; // the sensor value void setup() { diff --git a/examples/05.Control/switchCase/switchCase.ino b/examples/05.Control/switchCase/switchCase.ino index 3ffc9f0..f964b61 100644 --- a/examples/05.Control/switchCase/switchCase.ino +++ b/examples/05.Control/switchCase/switchCase.ino @@ -23,8 +23,8 @@ // these constants won't change. They are the lowest and highest readings you // get from your sensor: -const int sensorMin = 0; // sensor minimum, discovered through experiment -const int sensorMax = 600; // sensor maximum, discovered through experiment +const int sensorMin = 0; // sensor minimum, discovered through experiment +const int sensorMax = 600; // sensor maximum, discovered through experiment void setup() { // initialize serial communication: @@ -39,18 +39,18 @@ void loop() { // do something different depending on the range value: switch (range) { - case 0: // your hand is on the sensor + case 0: // your hand is on the sensor Serial.println("dark"); break; - case 1: // your hand is close to the sensor + case 1: // your hand is close to the sensor Serial.println("dim"); break; - case 2: // your hand is a few inches from the sensor + case 2: // your hand is a few inches from the sensor Serial.println("medium"); break; - case 3: // your hand is nowhere near the sensor + case 3: // your hand is nowhere near the sensor Serial.println("bright"); break; } - delay(1); // delay in between reads for stability + delay(1); // delay in between reads for stability } diff --git a/examples/06.Sensors/ADXL3xx/ADXL3xx.ino b/examples/06.Sensors/ADXL3xx/ADXL3xx.ino index 65b579b..b9dbf64 100644 --- a/examples/06.Sensors/ADXL3xx/ADXL3xx.ino +++ b/examples/06.Sensors/ADXL3xx/ADXL3xx.ino @@ -25,11 +25,11 @@ */ // these constants describe the pins. They won't change: -const int groundpin = 18; // analog input pin 4 -- ground -const int powerpin = 19; // analog input pin 5 -- voltage -const int xpin = A3; // x-axis of the accelerometer -const int ypin = A2; // y-axis -const int zpin = A1; // z-axis (only on 3-axis models) +const int groundpin = 18; // analog input pin 4 -- ground +const int powerpin = 19; // analog input pin 5 -- voltage +const int xpin = A3; // x-axis of the accelerometer +const int ypin = A2; // y-axis +const int zpin = A1; // z-axis (only on 3-axis models) void setup() { // initialize the serial communications: diff --git a/examples/06.Sensors/Knock/Knock.ino b/examples/06.Sensors/Knock/Knock.ino index 815d721..0e21486 100644 --- a/examples/06.Sensors/Knock/Knock.ino +++ b/examples/06.Sensors/Knock/Knock.ino @@ -23,17 +23,17 @@ // these constants won't change: -const int ledPin = 13; // LED connected to digital pin 13 -const int knockSensor = A0; // the piezo is connected to analog pin 0 -const int threshold = 100; // threshold value to decide when the detected sound is a knock or not +const int ledPin = 13; // LED connected to digital pin 13 +const int knockSensor = A0; // the piezo is connected to analog pin 0 +const int threshold = 100; // threshold value to decide when the detected sound is a knock or not // these variables will change: -int sensorReading = 0; // variable to store the value read from the sensor pin -int ledState = LOW; // variable used to store the last LED status, to toggle the light +int sensorReading = 0; // variable to store the value read from the sensor pin +int ledState = LOW; // variable used to store the last LED status, to toggle the light void setup() { - pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT + pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT Serial.begin(9600); // use the serial port } diff --git a/examples/06.Sensors/Memsic2125/Memsic2125.ino b/examples/06.Sensors/Memsic2125/Memsic2125.ino index b95472b..006306b 100644 --- a/examples/06.Sensors/Memsic2125/Memsic2125.ino +++ b/examples/06.Sensors/Memsic2125/Memsic2125.ino @@ -22,8 +22,8 @@ */ // these constants won't change: -const int xPin = 2; // X output of the accelerometer -const int yPin = 3; // Y output of the accelerometer +const int xPin = 2; // X output of the accelerometer +const int yPin = 3; // Y output of the accelerometer void setup() { // initialize serial communications: diff --git a/examples/07.Display/RowColumnScanning/RowColumnScanning.ino b/examples/07.Display/RowColumnScanning/RowColumnScanning.ino index 023a5c2..0fb04c5 100644 --- a/examples/07.Display/RowColumnScanning/RowColumnScanning.ino +++ b/examples/07.Display/RowColumnScanning/RowColumnScanning.ino @@ -83,7 +83,6 @@ void readSensors() { // set the new pixel position low so that the LED will turn on in the next // screen refresh: pixels[x][y] = LOW; - } void refreshScreen() { diff --git a/examples/07.Display/barGraph/barGraph.ino b/examples/07.Display/barGraph/barGraph.ino index ab97f13..b15f840 100644 --- a/examples/07.Display/barGraph/barGraph.ino +++ b/examples/07.Display/barGraph/barGraph.ino @@ -21,12 +21,12 @@ */ // these constants won't change: -const int analogPin = A0; // the pin that the potentiometer is attached to -const int ledCount = 10; // the number of LEDs in the bar graph +const int analogPin = A0; // the pin that the potentiometer is attached to +const int ledCount = 10; // the number of LEDs in the bar graph int ledPins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 -}; // an array of pin numbers to which LEDs are attached +}; // an array of pin numbers to which LEDs are attached void setup() { diff --git a/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino b/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino index e7a3c23..40d68a5 100644 --- a/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino +++ b/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -17,7 +17,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: diff --git a/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino b/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino index 531742b..4763acf 100644 --- a/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino +++ b/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -20,7 +20,7 @@ void setup() { // initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } stringOne = String("You added "); @@ -33,35 +33,36 @@ void setup() { void loop() { // adding a constant integer to a String: - stringThree = stringOne + 123; - Serial.println(stringThree); // prints "You added 123" + stringThree = stringOne + 123; + Serial.println(stringThree); // prints "You added 123" // adding a constant long integer to a String: stringThree = stringOne + 123456789; - Serial.println(stringThree); // prints "You added 123456789" + Serial.println(stringThree); // prints "You added 123456789" // adding a constant character to a String: - stringThree = stringOne + 'A'; - Serial.println(stringThree); // prints "You added A" + stringThree = stringOne + 'A'; + Serial.println(stringThree); // prints "You added A" // adding a constant string to a String: - stringThree = stringOne + "abc"; - Serial.println(stringThree); // prints "You added abc" + stringThree = stringOne + "abc"; + Serial.println(stringThree); // prints "You added abc" stringThree = stringOne + stringTwo; - Serial.println(stringThree); // prints "You added this string" + Serial.println(stringThree); // prints "You added this string" // adding a variable integer to a String: int sensorValue = analogRead(A0); stringOne = "Sensor value: "; - stringThree = stringOne + sensorValue; - Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has + stringThree = stringOne + sensorValue; + Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has // adding a variable long integer to a String: stringOne = "millis() value: "; stringThree = stringOne + millis(); - Serial.println(stringThree); // prints "The millis: 345345" or whatever value millis() has + Serial.println(stringThree); // prints "The millis: 345345" or whatever value millis() has // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino b/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino index b634892..4846cf4 100644 --- a/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino +++ b/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino @@ -18,7 +18,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } stringOne = String("Sensor "); @@ -41,11 +41,11 @@ void loop() { // adding a constant character to a String: stringOne += 'A'; - Serial.println(stringOne); // prints "Sensor value for input A" + Serial.println(stringOne); // prints "Sensor value for input A" // adding a constant integer to a String: stringOne += 0; - Serial.println(stringOne); // prints "Sensor value for input A0" + Serial.println(stringOne); // prints "Sensor value for input A0" // adding a constant string to a String: stringOne += ": "; @@ -53,7 +53,7 @@ void loop() { // adding a variable integer to a String: stringOne += analogRead(A0); - Serial.println(stringOne); // prints "Sensor value for input A0: 456" or whatever analogRead(A0) is + Serial.println(stringOne); // prints "Sensor value for input A0: 456" or whatever analogRead(A0) is Serial.println("\n\nchanging the Strings' values"); stringOne = "A long integer: "; @@ -61,12 +61,13 @@ void loop() { // adding a constant long integer to a String: stringOne += 123456789; - Serial.println(stringOne); // prints "A long integer: 123456789" + Serial.println(stringOne); // prints "A long integer: 123456789" // using concat() to add a long variable to a String: stringTwo.concat(millis()); - Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is + Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino b/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino index fc6ab61..52d4de8 100644 --- a/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino +++ b/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino @@ -16,7 +16,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: @@ -39,5 +39,6 @@ void loop() { // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringCharacters/StringCharacters.ino b/examples/08.Strings/StringCharacters/StringCharacters.ino index a179cfa..6c64b57 100644 --- a/examples/08.Strings/StringCharacters/StringCharacters.ino +++ b/examples/08.Strings/StringCharacters/StringCharacters.ino @@ -16,7 +16,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } Serial.println("\n\nString charAt() and setCharAt():"); @@ -41,5 +41,6 @@ void loop() { Serial.println(reportString); // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino b/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino index aff9139..4e57469 100644 --- a/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino +++ b/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -18,7 +18,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } @@ -27,7 +27,6 @@ void setup() { // send an intro: Serial.println("\n\nComparing Strings:"); Serial.println(); - } void loop() { @@ -122,7 +121,6 @@ void loop() { Serial.println(stringOne + " comes before " + stringTwo); } else { Serial.println(stringOne + " comes after " + stringTwo); - } } } diff --git a/examples/08.Strings/StringConstructors/StringConstructors.ino b/examples/08.Strings/StringConstructors/StringConstructors.ino index 85d0024..36ff78a 100644 --- a/examples/08.Strings/StringConstructors/StringConstructors.ino +++ b/examples/08.Strings/StringConstructors/StringConstructors.ino @@ -16,7 +16,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: @@ -27,42 +27,42 @@ void setup() { void loop() { // using a constant String: String stringOne = "Hello String"; - Serial.println(stringOne); // prints "Hello String" + Serial.println(stringOne); // prints "Hello String" // converting a constant char into a String: - stringOne = String('a'); - Serial.println(stringOne); // prints "a" + stringOne = String('a'); + Serial.println(stringOne); // prints "a" // converting a constant string into a String object: - String stringTwo = String("This is a string"); - Serial.println(stringTwo); // prints "This is a string" + String stringTwo = String("This is a string"); + Serial.println(stringTwo); // prints "This is a string" // concatenating two strings: - stringOne = String(stringTwo + " with more"); + stringOne = String(stringTwo + " with more"); // prints "This is a string with more": Serial.println(stringOne); // using a constant integer: - stringOne = String(13); - Serial.println(stringOne); // prints "13" + stringOne = String(13); + Serial.println(stringOne); // prints "13" // using an int and a base: - stringOne = String(analogRead(A0), DEC); + stringOne = String(analogRead(A0), DEC); // prints "453" or whatever the value of analogRead(A0) is Serial.println(stringOne); // using an int and a base (hexadecimal): - stringOne = String(45, HEX); + stringOne = String(45, HEX); // prints "2d", which is the hexadecimal version of decimal 45: Serial.println(stringOne); // using an int and a base (binary) - stringOne = String(255, BIN); + stringOne = String(255, BIN); // prints "11111111" which is the binary value of 255 Serial.println(stringOne); // using a long and a base: - stringOne = String(millis(), DEC); + stringOne = String(millis(), DEC); // prints "123456" or whatever the value of millis() is: Serial.println(stringOne); @@ -75,6 +75,6 @@ void loop() { Serial.println(stringOne); // do nothing while true: - while (true); - + while (true) + ; } diff --git a/examples/08.Strings/StringIndexOf/StringIndexOf.ino b/examples/08.Strings/StringIndexOf/StringIndexOf.ino index 219f508..cf1f816 100644 --- a/examples/08.Strings/StringIndexOf/StringIndexOf.ino +++ b/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -16,7 +16,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: @@ -50,7 +50,7 @@ void loop() { int lastOpeningBracket = stringOne.lastIndexOf('<'); Serial.println("The index of the last < in the string " + stringOne + " is " + lastOpeningBracket); - int lastListItem = stringOne.lastIndexOf("
  • "); + int lastListItem = stringOne.lastIndexOf("
  • "); Serial.println("The index of the last list tag in the string " + stringOne + " is " + lastListItem); @@ -61,5 +61,6 @@ void loop() { Serial.println("The index of the second to last paragraph tag " + stringOne + " is " + secondLastGraf); // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringLength/StringLength.ino b/examples/08.Strings/StringLength/StringLength.ino index ef57b74..c9378a7 100644 --- a/examples/08.Strings/StringLength/StringLength.ino +++ b/examples/08.Strings/StringLength/StringLength.ino @@ -12,14 +12,14 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringLengthTrim */ -String txtMsg = ""; // a string for incoming text -unsigned int lastStringLength = txtMsg.length(); // previous length of the String +String txtMsg = ""; // a string for incoming text +unsigned int lastStringLength = txtMsg.length(); // previous length of the String void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: diff --git a/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino b/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino index b253087..bdef83a 100644 --- a/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino +++ b/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -16,7 +16,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: @@ -38,5 +38,6 @@ void loop() { Serial.println(stringOne.length()); // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringReplace/StringReplace.ino b/examples/08.Strings/StringReplace/StringReplace.ino index 907f5d0..6fa9ba1 100644 --- a/examples/08.Strings/StringReplace/StringReplace.ino +++ b/examples/08.Strings/StringReplace/StringReplace.ino @@ -16,7 +16,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: @@ -46,5 +46,6 @@ void loop() { Serial.println("l33tspeak: " + leetString); // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino b/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino index ff5563c..9cdbe24 100644 --- a/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino +++ b/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino @@ -16,7 +16,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: @@ -49,5 +49,6 @@ void loop() { } // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringSubstring/StringSubstring.ino b/examples/08.Strings/StringSubstring/StringSubstring.ino index 1c0854a..871da29 100644 --- a/examples/08.Strings/StringSubstring/StringSubstring.ino +++ b/examples/08.Strings/StringSubstring/StringSubstring.ino @@ -16,7 +16,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: @@ -39,5 +39,6 @@ void loop() { } // do nothing while true: - while (true); + while (true) + ; } diff --git a/examples/08.Strings/StringToInt/StringToInt.ino b/examples/08.Strings/StringToInt/StringToInt.ino index 81e48e5..dc10d02 100644 --- a/examples/08.Strings/StringToInt/StringToInt.ino +++ b/examples/08.Strings/StringToInt/StringToInt.ino @@ -15,13 +15,13 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringToInt */ -String inString = ""; // string to hold input +String inString = ""; // string to hold input void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // send an intro: diff --git a/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino b/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino index 28c59f9..c44c509 100644 --- a/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino +++ b/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino @@ -85,5 +85,6 @@ void loop() { } // do nothing: - while (true); + while (true) + ; } diff --git a/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino b/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino index f0bd32b..fbf4adb 100644 --- a/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino +++ b/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -22,9 +22,9 @@ #include "Keyboard.h" -const int buttonPin = 4; // input pin for pushbutton -int previousButtonState = HIGH; // for checking the state of a pushButton -int counter = 0; // button push counter +const int buttonPin = 4; // input pin for pushbutton +int previousButtonState = HIGH; // for checking the state of a pushButton +int counter = 0; // button push counter void setup() { // make the pushButton pin an input: diff --git a/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino index d86f944..94efe8c 100644 --- a/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino +++ b/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -99,5 +99,6 @@ void loop() { Keyboard.releaseAll(); // wait for the sweet oblivion of reprogramming: - while (true); + while (true) + ; } diff --git a/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino b/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino index 8850067..3b1a280 100644 --- a/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino +++ b/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino @@ -31,7 +31,7 @@ const int leftButton = 4; const int rightButton = 5; const int mouseButton = 6; -void setup() { // initialize the buttons' inputs: +void setup() { // initialize the buttons' inputs: pinMode(upButton, INPUT); pinMode(downButton, INPUT); pinMode(leftButton, INPUT); @@ -89,5 +89,4 @@ void loop() { if (digitalRead(mouseButton) == HIGH) { Keyboard.write('m'); } - } diff --git a/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino b/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino index 2e0da7a..c27ef70 100644 --- a/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino +++ b/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino @@ -32,8 +32,8 @@ const int leftButton = 4; const int rightButton = 5; const int mouseButton = 6; -int range = 5; // output range of X or Y movement; affects movement speed -int responseDelay = 10; // response delay of the mouse, in ms +int range = 5; // output range of X or Y movement; affects movement speed +int responseDelay = 10; // response delay of the mouse, in ms void setup() { @@ -56,8 +56,8 @@ void loop() { int clickState = digitalRead(mouseButton); // calculate the movement distance based on the button states: - int xDistance = (leftState - rightState) * range; - int yDistance = (upState - downState) * range; + int xDistance = (leftState - rightState) * range; + int yDistance = (upState - downState) * range; // if X or Y is non-zero, move: if ((xDistance != 0) || (yDistance != 0)) { diff --git a/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino b/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino index 92d00f6..266ba61 100644 --- a/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino +++ b/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino @@ -32,24 +32,24 @@ #include "Mouse.h" // set pin numbers for switch, joystick axes, and LED: -const int switchPin = 2; // switch to turn on and off mouse control -const int mouseButton = 3; // input pin for the mouse pushButton -const int xAxis = A0; // joystick X axis -const int yAxis = A1; // joystick Y axis -const int ledPin = 5; // Mouse control LED +const int switchPin = 2; // switch to turn on and off mouse control +const int mouseButton = 3; // input pin for the mouse pushButton +const int xAxis = A0; // joystick X axis +const int yAxis = A1; // joystick Y axis +const int ledPin = 5; // Mouse control LED // parameters for reading the joystick: -int range = 12; // output range of X or Y movement -int responseDelay = 5; // response delay of the mouse, in ms -int threshold = range / 4; // resting threshold -int center = range / 2; // resting position value +int range = 12; // output range of X or Y movement +int responseDelay = 5; // response delay of the mouse, in ms +int threshold = range / 4; // resting threshold +int center = range / 2; // resting position value -bool mouseIsActive = false; // whether or not to control the mouse -int lastSwitchState = LOW; // previous switch state +bool mouseIsActive = false; // whether or not to control the mouse +int lastSwitchState = LOW; // previous switch state void setup() { - pinMode(switchPin, INPUT); // the switch pin - pinMode(ledPin, OUTPUT); // the LED pin + pinMode(switchPin, INPUT); // the switch pin + pinMode(ledPin, OUTPUT); // the LED pin // take control of the mouse: Mouse.begin(); } diff --git a/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino b/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino index 5acf9de..255d100 100644 --- a/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino +++ b/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino @@ -42,21 +42,21 @@ void loop() { // if the button is not pressed turn on the green LED and off the red LEDs if (switchstate == LOW) { - digitalWrite(3, HIGH); // turn the green LED on pin 3 on - digitalWrite(4, LOW); // turn the red LED on pin 4 off - digitalWrite(5, LOW); // turn the red LED on pin 5 off + digitalWrite(3, HIGH); // turn the green LED on pin 3 on + digitalWrite(4, LOW); // turn the red LED on pin 4 off + digitalWrite(5, LOW); // turn the red LED on pin 5 off } // this else is part of the above if() statement. // if the switch is not LOW (the button is pressed) turn off the green LED and // blink alternatively the red LEDs else { - digitalWrite(3, LOW); // turn the green LED on pin 3 off - digitalWrite(4, LOW); // turn the red LED on pin 4 off - digitalWrite(5, HIGH); // turn the red LED on pin 5 on + digitalWrite(3, LOW); // turn the green LED on pin 3 off + digitalWrite(4, LOW); // turn the red LED on pin 4 off + digitalWrite(5, HIGH); // turn the red LED on pin 5 on // wait for a quarter second before changing the light delay(250); - digitalWrite(4, HIGH); // turn the red LED on pin 4 on - digitalWrite(5, LOW); // turn the red LED on pin 5 off + digitalWrite(4, HIGH); // turn the red LED on pin 4 on + digitalWrite(5, LOW); // turn the red LED on pin 5 off // wait for a quarter second before changing the light delay(250); } diff --git a/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino b/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino index 57959ed..e8390a3 100644 --- a/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino +++ b/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino @@ -61,17 +61,17 @@ void loop() { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); - } // if the temperature rises 2-4 degrees, turn an LED on + } // if the temperature rises 2-4 degrees, turn an LED on else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) { digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, LOW); - } // if the temperature rises 4-6 degrees, turn a second LED on + } // if the temperature rises 4-6 degrees, turn a second LED on else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); - } // if the temperature rises more than 6 degrees, turn all LEDs on + } // if the temperature rises more than 6 degrees, turn all LEDs on else if (temperature >= baselineTemp + 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); diff --git a/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino b/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino index 09f3121..8efc411 100644 --- a/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino +++ b/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino @@ -21,21 +21,21 @@ This example code is part of the public domain. */ -const int greenLEDPin = 9; // LED connected to digital pin 9 -const int redLEDPin = 10; // LED connected to digital pin 10 -const int blueLEDPin = 11; // LED connected to digital pin 11 +const int greenLEDPin = 9; // LED connected to digital pin 9 +const int redLEDPin = 10; // LED connected to digital pin 10 +const int blueLEDPin = 11; // LED connected to digital pin 11 -const int redSensorPin = A0; // pin with the photoresistor with the red gel -const int greenSensorPin = A1; // pin with the photoresistor with the green gel +const int redSensorPin = A0; // pin with the photoresistor with the red gel +const int greenSensorPin = A1; // pin with the photoresistor with the green gel const int blueSensorPin = A2; // pin with the photoresistor with the blue gel -int redValue = 0; // value to write to the red LED -int greenValue = 0; // value to write to the green LED -int blueValue = 0; // value to write to the blue LED +int redValue = 0; // value to write to the red LED +int greenValue = 0; // value to write to the green LED +int blueValue = 0; // value to write to the blue LED -int redSensorValue = 0; // variable to hold the value from the red sensor -int greenSensorValue = 0; // variable to hold the value from the green sensor -int blueSensorValue = 0; // variable to hold the value from the blue sensor +int redSensorValue = 0; // variable to hold the value from the red sensor +int greenSensorValue = 0; // variable to hold the value from the green sensor +int blueSensorValue = 0; // variable to hold the value from the blue sensor void setup() { // initialize serial communications at 9600 bps: diff --git a/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino b/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino index 9e042ed..5e2ccf3 100644 --- a/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino +++ b/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino @@ -22,17 +22,17 @@ Servo myServo; // create a servo object -int const potPin = A0; // analog pin used to connect the potentiometer -int potVal; // variable to read the value from the analog pin -int angle; // variable to hold the angle for the servo motor +int const potPin = A0; // analog pin used to connect the potentiometer +int potVal; // variable to read the value from the analog pin +int angle; // variable to hold the angle for the servo motor void setup() { - myServo.attach(9); // attaches the servo on pin 9 to the servo object - Serial.begin(9600); // open a serial connection to your computer + myServo.attach(9); // attaches the servo on pin 9 to the servo object + Serial.begin(9600); // open a serial connection to your computer } void loop() { - potVal = analogRead(potPin); // read the value of the potentiometer + potVal = analogRead(potPin); // read the value of the potentiometer // print out the value to the Serial Monitor Serial.print("potVal: "); Serial.print(potVal); diff --git a/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino b/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino index bf53da7..f6b6fb3 100644 --- a/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino +++ b/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino @@ -21,7 +21,7 @@ // create an array of notes // the numbers below correspond to the frequencies of middle C, D, E, and F -int notes[] = {262, 294, 330, 349}; +int notes[] = { 262, 294, 330, 349 }; void setup() { //start serial communication diff --git a/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino b/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino index 0d7004b..9fbbc18 100644 --- a/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino +++ b/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino @@ -21,13 +21,13 @@ // named constant for the switch pin const int switchPin = 8; -unsigned long previousTime = 0; // store the last time an LED was updated -int switchState = 0; // the current switch state -int prevSwitchState = 0; // the previous switch state -int led = 2; // a variable to refer to the LEDs +unsigned long previousTime = 0; // store the last time an LED was updated +int switchState = 0; // the current switch state +int prevSwitchState = 0; // the previous switch state +int led = 2; // a variable to refer to the LEDs // 600000 = 10 minutes in milliseconds -long interval = 600000; // interval at which to light the next LED +long interval = 600000; // interval at which to light the next LED void setup() { // set the LED pins as outputs diff --git a/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino b/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino index 56c465d..8841d32 100644 --- a/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino +++ b/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino @@ -21,8 +21,8 @@ */ // named constants for the switch and motor pins -const int switchPin = 2; // the number of the switch pin -const int motorPin = 9; // the number of the motor pin +const int switchPin = 2; // the number of the switch pin +const int motorPin = 9; // the number of the motor pin int switchState = 0; // variable for reading the switch's status diff --git a/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino b/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino index 69ac37e..9b9991f 100644 --- a/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino +++ b/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino @@ -21,22 +21,22 @@ This example code is part of the public domain. */ -const int controlPin1 = 2; // connected to pin 7 on the H-bridge -const int controlPin2 = 3; // connected to pin 2 on the H-bridge -const int enablePin = 9; // connected to pin 1 on the H-bridge -const int directionSwitchPin = 4; // connected to the switch for direction -const int onOffSwitchStateSwitchPin = 5; // connected to the switch for turning the motor on and off -const int potPin = A0; // connected to the potentiometer's output +const int controlPin1 = 2; // connected to pin 7 on the H-bridge +const int controlPin2 = 3; // connected to pin 2 on the H-bridge +const int enablePin = 9; // connected to pin 1 on the H-bridge +const int directionSwitchPin = 4; // connected to the switch for direction +const int onOffSwitchStateSwitchPin = 5; // connected to the switch for turning the motor on and off +const int potPin = A0; // connected to the potentiometer's output // create some variables to hold values from your inputs -int onOffSwitchState = 0; // current state of the on/off switch -int previousOnOffSwitchState = 0; // previous position of the on/off switch -int directionSwitchState = 0; // current state of the direction switch +int onOffSwitchState = 0; // current state of the on/off switch +int previousOnOffSwitchState = 0; // previous position of the on/off switch +int directionSwitchState = 0; // current state of the direction switch int previousDirectionSwitchState = 0; // previous state of the direction switch -int motorEnabled = 0; // Turns the motor on/off -int motorSpeed = 0; // speed of the motor -int motorDirection = 1; // current direction of the motor +int motorEnabled = 0; // Turns the motor on/off +int motorSpeed = 0; // speed of the motor +int motorDirection = 1; // current direction of the motor void setup() { // initialize the inputs and outputs @@ -92,7 +92,7 @@ void loop() { if (motorEnabled == 1) { // PWM the enable pin to vary the speed analogWrite(enablePin, motorSpeed); - } else { // if the motor is not supposed to be on + } else { // if the motor is not supposed to be on //turn the motor off analogWrite(enablePin, 0); } diff --git a/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino b/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino index a952307..6401ac9 100644 --- a/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino +++ b/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino @@ -30,11 +30,11 @@ // create an instance of the Servo library Servo myServo; -const int piezo = A0; // pin the piezo is attached to -const int switchPin = 2; // pin the switch is attached to -const int yellowLed = 3; // pin the yellow LED is attached to -const int greenLed = 4; // pin the green LED is attached to -const int redLed = 5; // pin the red LED is attached to +const int piezo = A0; // pin the piezo is attached to +const int switchPin = 2; // pin the switch is attached to +const int yellowLed = 3; // pin the yellow LED is attached to +const int greenLed = 4; // pin the green LED is attached to +const int redLed = 5; // pin the red LED is attached to // variable for the piezo value int knockVal; diff --git a/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino b/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino index 28daed0..9db4bbf 100644 --- a/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino +++ b/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino @@ -17,7 +17,7 @@ This example code is part of the public domain. */ -const int optoPin = 2; // the pin the optocoupler is connected to +const int optoPin = 2; // the pin the optocoupler is connected to void setup() { // make the pin with the optocoupler an output @@ -27,7 +27,7 @@ void setup() { void loop() { digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler - delay(15); // give the optocoupler a moment to activate + delay(15); // give the optocoupler a moment to activate digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again delay(21000); // wait for 21 seconds diff --git a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 3f84d6b..c75d233 100644 --- a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -50,7 +50,7 @@ // // A clock slow enough for an ATtiny85 @ 1 MHz, is a reasonable default: -#define SPI_CLOCK (1000000/6) +#define SPI_CLOCK (1000000 / 6) // Select hardware or software SPI, depending on SPI clock. @@ -59,9 +59,9 @@ #if defined(ARDUINO_ARCH_AVR) - #if SPI_CLOCK > (F_CPU / 128) - #define USE_HARDWARE_SPI - #endif +#if SPI_CLOCK > (F_CPU / 128) +#define USE_HARDWARE_SPI +#endif #endif @@ -70,51 +70,51 @@ // The standard pin configuration. #ifndef ARDUINO_HOODLOADER2 - #define RESET 10 // Use pin 10 to reset the target rather than SS - #define LED_HB 9 - #define LED_ERR 8 - #define LED_PMODE 7 +#define RESET 10 // Use pin 10 to reset the target rather than SS +#define LED_HB 9 +#define LED_ERR 8 +#define LED_PMODE 7 - // Uncomment following line to use the old Uno style wiring - // (using pin 11, 12 and 13 instead of the SPI header) on Leonardo, Due... +// Uncomment following line to use the old Uno style wiring +// (using pin 11, 12 and 13 instead of the SPI header) on Leonardo, Due... - // #define USE_OLD_STYLE_WIRING +// #define USE_OLD_STYLE_WIRING - #ifdef USE_OLD_STYLE_WIRING +#ifdef USE_OLD_STYLE_WIRING - #define PIN_MOSI 11 - #define PIN_MISO 12 - #define PIN_SCK 13 +#define PIN_MOSI 11 +#define PIN_MISO 12 +#define PIN_SCK 13 - #endif +#endif - // HOODLOADER2 means running sketches on the ATmega16U2 serial converter chips - // on Uno or Mega boards. We must use pins that are broken out: +// HOODLOADER2 means running sketches on the ATmega16U2 serial converter chips +// on Uno or Mega boards. We must use pins that are broken out: #else - #define RESET 4 - #define LED_HB 7 - #define LED_ERR 6 - #define LED_PMODE 5 +#define RESET 4 +#define LED_HB 7 +#define LED_ERR 6 +#define LED_PMODE 5 #endif // By default, use hardware SPI pins: #ifndef PIN_MOSI - #define PIN_MOSI MOSI +#define PIN_MOSI MOSI #endif #ifndef PIN_MISO - #define PIN_MISO MISO +#define PIN_MISO MISO #endif #ifndef PIN_SCK - #define PIN_SCK SCK +#define PIN_SCK SCK #endif // Force bitbanged SPI if not using the hardware SPI pins: -#if (PIN_MISO != MISO) || (PIN_MOSI != MOSI) || (PIN_SCK != SCK) - #undef USE_HARDWARE_SPI +#if (PIN_MISO != MISO) || (PIN_MOSI != MOSI) || (PIN_SCK != SCK) +#undef USE_HARDWARE_SPI #endif @@ -131,15 +131,15 @@ // To use 'Serial': #define SERIAL Serial #ifdef SERIAL_PORT_USBVIRTUAL - #define SERIAL SERIAL_PORT_USBVIRTUAL +#define SERIAL SERIAL_PORT_USBVIRTUAL #else - #define SERIAL Serial +#define SERIAL Serial #endif // Configure the baud rate: -#define BAUDRATE 19200 +#define BAUDRATE 19200 // #define BAUDRATE 115200 // #define BAUDRATE 1000000 @@ -149,12 +149,12 @@ #define SWMIN 18 // STK Definitions -#define STK_OK 0x10 -#define STK_FAILED 0x11 +#define STK_OK 0x10 +#define STK_FAILED 0x11 #define STK_UNKNOWN 0x12 -#define STK_INSYNC 0x14 -#define STK_NOSYNC 0x15 -#define CRC_EOP 0x20 //ok it is a space... +#define STK_INSYNC 0x14 +#define STK_NOSYNC 0x15 +#define CRC_EOP 0x20 //ok it is a space... void pulse(int pin, int times); @@ -164,57 +164,58 @@ void pulse(int pin, int times); #define SPI_MODE0 0x00 -#if !defined(ARDUINO_API_VERSION) || ARDUINO_API_VERSION != 10001 // A SPISettings class is declared by ArduinoCore-API 1.0.1 +#if !defined(ARDUINO_API_VERSION) || ARDUINO_API_VERSION != 10001 // A SPISettings class is declared by ArduinoCore-API 1.0.1 class SPISettings { - public: - // clock is in Hz - SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clockFreq(clock) { - (void) bitOrder; - (void) dataMode; - }; - - uint32_t getClockFreq() const { - return clockFreq; - } +public: + // clock is in Hz + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) + : clockFreq(clock) { + (void)bitOrder; + (void)dataMode; + }; + + uint32_t getClockFreq() const { + return clockFreq; + } - private: - uint32_t clockFreq; +private: + uint32_t clockFreq; }; -#endif // !defined(ARDUINO_API_VERSION) +#endif // !defined(ARDUINO_API_VERSION) class BitBangedSPI { - public: - void begin() { - digitalWrite(PIN_SCK, LOW); - digitalWrite(PIN_MOSI, LOW); - pinMode(PIN_SCK, OUTPUT); - pinMode(PIN_MOSI, OUTPUT); - pinMode(PIN_MISO, INPUT); - } +public: + void begin() { + digitalWrite(PIN_SCK, LOW); + digitalWrite(PIN_MOSI, LOW); + pinMode(PIN_SCK, OUTPUT); + pinMode(PIN_MOSI, OUTPUT); + pinMode(PIN_MISO, INPUT); + } - void beginTransaction(SPISettings settings) { - pulseWidth = (500000 + settings.getClockFreq() - 1) / settings.getClockFreq(); - if (pulseWidth == 0) { - pulseWidth = 1; - } + void beginTransaction(SPISettings settings) { + pulseWidth = (500000 + settings.getClockFreq() - 1) / settings.getClockFreq(); + if (pulseWidth == 0) { + pulseWidth = 1; } + } - void end() {} + void end() {} - uint8_t transfer(uint8_t b) { - for (unsigned int i = 0; i < 8; ++i) { - digitalWrite(PIN_MOSI, (b & 0x80) ? HIGH : LOW); - digitalWrite(PIN_SCK, HIGH); - delayMicroseconds(pulseWidth); - b = (b << 1) | digitalRead(PIN_MISO); - digitalWrite(PIN_SCK, LOW); // slow pulse - delayMicroseconds(pulseWidth); - } - return b; + uint8_t transfer(uint8_t b) { + for (unsigned int i = 0; i < 8; ++i) { + digitalWrite(PIN_MOSI, (b & 0x80) ? HIGH : LOW); + digitalWrite(PIN_SCK, HIGH); + delayMicroseconds(pulseWidth); + b = (b << 1) | digitalRead(PIN_MISO); + digitalWrite(PIN_SCK, LOW); // slow pulse + delayMicroseconds(pulseWidth); } + return b; + } - private: - unsigned long pulseWidth; // in microseconds +private: + unsigned long pulseWidth; // in microseconds }; static BitBangedSPI SPI; @@ -230,16 +231,15 @@ void setup() { pulse(LED_ERR, 2); pinMode(LED_HB, OUTPUT); pulse(LED_HB, 2); - } int ISPError = 0; int pmode = 0; // address for reading and writing, set by 'U' command unsigned int here; -uint8_t buff[256]; // global block storage +uint8_t buff[256]; // global block storage -#define beget16(addr) (*addr * 256 + *(addr+1) ) +#define beget16(addr) (*addr * 256 + *(addr + 1)) typedef struct param { uint8_t devicecode; uint8_t revision; @@ -254,8 +254,7 @@ typedef struct param { uint16_t pagesize; uint16_t eepromsize; uint32_t flashsize; -} -parameter; +} parameter; parameter param; @@ -307,7 +306,8 @@ void loop(void) { } uint8_t getch() { - while (!SERIAL.available()); + while (!SERIAL.available()) + ; return SERIAL.read(); } void fill(int n) { @@ -372,7 +372,7 @@ void get_version(uint8_t c) { breply(SWMIN); break; case 0x93: - breply('S'); // serial programmer + breply('S'); // serial programmer break; default: breply(0); @@ -382,18 +382,18 @@ void get_version(uint8_t c) { void set_parameters() { // call this after reading parameter packet into buff[] param.devicecode = buff[0]; - param.revision = buff[1]; - param.progtype = buff[2]; - param.parmode = buff[3]; - param.polling = buff[4]; - param.selftimed = buff[5]; - param.lockbytes = buff[6]; - param.fusebytes = buff[7]; - param.flashpoll = buff[8]; + param.revision = buff[1]; + param.progtype = buff[2]; + param.parmode = buff[3]; + param.polling = buff[4]; + param.selftimed = buff[5]; + param.lockbytes = buff[6]; + param.fusebytes = buff[7]; + param.flashpoll = buff[8]; // ignore buff[9] (= buff[8]) // following are 16 bits (big endian) param.eeprompoll = beget16(&buff[10]); - param.pagesize = beget16(&buff[12]); + param.pagesize = beget16(&buff[12]); param.eepromsize = beget16(&buff[14]); // 32 bits flashsize (big endian) @@ -423,7 +423,7 @@ void start_pmode() { // Pulse RESET after PIN_SCK is low: digitalWrite(PIN_SCK, LOW); - delay(20); // discharge PIN_SCK, value arbitrarily chosen + delay(20); // discharge PIN_SCK, value arbitrarily chosen reset_target(false); // Pulse must be minimum 2 target CPU clock cycles so 100 usec is ok for CPU // speeds above 20 KHz @@ -431,7 +431,7 @@ void start_pmode() { reset_target(true); // Send the enable programming command: - delay(50); // datasheet: must be > 20 msec + delay(50); // datasheet: must be > 20 msec spi_transaction(0xAC, 0x53, 0x00, 0x00); pmode = 1; } @@ -491,11 +491,11 @@ unsigned int current_page() { void write_flash(int length) { fill(length); if (CRC_EOP == getch()) { - SERIAL.print((char) STK_INSYNC); - SERIAL.print((char) write_flash_pages(length)); + SERIAL.print((char)STK_INSYNC); + SERIAL.print((char)write_flash_pages(length)); } else { ISPError++; - SERIAL.print((char) STK_NOSYNC); + SERIAL.print((char)STK_NOSYNC); } } @@ -549,7 +549,7 @@ uint8_t write_eeprom_chunk(unsigned int start, unsigned int length) { } void program_page() { - char result = (char) STK_FAILED; + char result = (char)STK_FAILED; unsigned int length = 256 * getch(); length += getch(); char memtype = getch(); @@ -561,11 +561,11 @@ void program_page() { if (memtype == 'E') { result = (char)write_eeprom(length); if (CRC_EOP == getch()) { - SERIAL.print((char) STK_INSYNC); + SERIAL.print((char)STK_INSYNC); SERIAL.print(result); } else { ISPError++; - SERIAL.print((char) STK_NOSYNC); + SERIAL.print((char)STK_NOSYNC); } return; } @@ -583,9 +583,9 @@ uint8_t flash_read(uint8_t hilo, unsigned int addr) { char flash_read_page(int length) { for (int x = 0; x < length; x += 2) { uint8_t low = flash_read(LOW, here); - SERIAL.print((char) low); + SERIAL.print((char)low); uint8_t high = flash_read(HIGH, here); - SERIAL.print((char) high); + SERIAL.print((char)high); here++; } return STK_OK; @@ -597,7 +597,7 @@ char eeprom_read_page(int length) { for (int x = 0; x < length; x++) { int addr = start + x; uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF); - SERIAL.print((char) ee); + SERIAL.print((char)ee); } return STK_OK; } @@ -609,10 +609,10 @@ void read_page() { char memtype = getch(); if (CRC_EOP != getch()) { ISPError++; - SERIAL.print((char) STK_NOSYNC); + SERIAL.print((char)STK_NOSYNC); return; } - SERIAL.print((char) STK_INSYNC); + SERIAL.print((char)STK_INSYNC); if (memtype == 'F') { result = flash_read_page(length); } @@ -625,17 +625,17 @@ void read_page() { void read_signature() { if (CRC_EOP != getch()) { ISPError++; - SERIAL.print((char) STK_NOSYNC); + SERIAL.print((char)STK_NOSYNC); return; } - SERIAL.print((char) STK_INSYNC); + SERIAL.print((char)STK_INSYNC); uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00); - SERIAL.print((char) high); + SERIAL.print((char)high); uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00); - SERIAL.print((char) middle); + SERIAL.print((char)middle); uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00); - SERIAL.print((char) low); - SERIAL.print((char) STK_OK); + SERIAL.print((char)low); + SERIAL.print((char)STK_OK); } ////////////////////////////////////////// ////////////////////////////////////////// @@ -646,18 +646,18 @@ void read_signature() { void avrisp() { uint8_t ch = getch(); switch (ch) { - case '0': // signon + case '0': // signon ISPError = 0; empty_reply(); break; case '1': if (getch() == CRC_EOP) { - SERIAL.print((char) STK_INSYNC); + SERIAL.print((char)STK_INSYNC); SERIAL.print("AVR ISP"); - SERIAL.print((char) STK_OK); + SERIAL.print((char)STK_OK); } else { ISPError++; - SERIAL.print((char) STK_NOSYNC); + SERIAL.print((char)STK_NOSYNC); } break; case 'A': @@ -668,7 +668,7 @@ void avrisp() { set_parameters(); empty_reply(); break; - case 'E': // extended parameters - ignore for now + case 'E': // extended parameters - ignore for now fill(5); empty_reply(); break; @@ -678,40 +678,40 @@ void avrisp() { } empty_reply(); break; - case 'U': // set address (word) + case 'U': // set address (word) here = getch(); here += 256 * getch(); empty_reply(); break; - case 0x60: //STK_PROG_FLASH - getch(); // low addr - getch(); // high addr + case 0x60: //STK_PROG_FLASH + getch(); // low addr + getch(); // high addr empty_reply(); break; - case 0x61: //STK_PROG_DATA - getch(); // data + case 0x61: //STK_PROG_DATA + getch(); // data empty_reply(); break; - case 0x64: //STK_PROG_PAGE + case 0x64: //STK_PROG_PAGE program_page(); break; - case 0x74: //STK_READ_PAGE 't' + case 0x74: //STK_READ_PAGE 't' read_page(); break; - case 'V': //0x56 + case 'V': //0x56 universal(); break; - case 'Q': //0x51 + case 'Q': //0x51 ISPError = 0; end_pmode(); empty_reply(); break; - case 0x75: //STK_READ_SIGN 'u' + case 0x75: //STK_READ_SIGN 'u' read_signature(); break; @@ -719,7 +719,7 @@ void avrisp() { // this is how we can get back in sync case CRC_EOP: ISPError++; - SERIAL.print((char) STK_NOSYNC); + SERIAL.print((char)STK_NOSYNC); break; // anything else we will return STK_UNKNOWN diff --git a/examples_formatter.conf b/examples_formatter.conf deleted file mode 100644 index e006d1f..0000000 --- a/examples_formatter.conf +++ /dev/null @@ -1,45 +0,0 @@ -# This configuration file contains a selection of the available options provided by the formatting tool "Artistic Style" -# http://astyle.sourceforge.net/astyle.html -# -# If you wish to change them, don't edit this file. -# Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE -# If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link - -mode=c - -# 2 spaces indentation -indent=spaces=2 - -# also indent macros -indent-preprocessor - -# indent classes, switches (and cases), comments starting at column 1 -indent-classes -indent-switches -indent-cases -indent-col1-comments - -# put a space around operators -pad-oper - -# put a space after if/for/while -pad-header - -# if you like one-liners, keep them -keep-one-line-statements - -style=java -attach-namespaces -attach-classes -attach-inlines -attach-extern-c -indent-modifiers -indent-namespaces -indent-labels -indent-preproc-block -indent-preproc-define -indent-preproc-cond -unpad-paren -add-brackets -remove-comment-prefix - diff --git a/examples_formatter.sh b/examples_formatter.sh index 475c2a4..23ecfe8 100755 --- a/examples_formatter.sh +++ b/examples_formatter.sh @@ -1,5 +1,5 @@ -if ! which astyle &>/dev/null; then - echo "astyle not found or not in PATH. Please install: https://astyle.sourceforge.net/install.html" +if ! which clang-format &>/dev/null; then + echo "clang-format not found or not in PATH. Please install: https://github.com/arduino/clang-static-binaries/releases" exit 1 fi @@ -15,6 +15,8 @@ find \ \) \ -type f \ -exec \ - astyle \ - --options=examples_formatter.conf \ + clang-format \ + --assume-filename=foo.cpp \ + -i \ + --style=file \ {} \;