diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..94e8e06 Binary files /dev/null and b/.DS_Store differ 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/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 0000000..f538bc8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,56 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/issue-templates/forms/general/bug-report.yml +# See: https://docs.github.com/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms + +name: Bug report +description: Report a problem with the code or documentation in this repository. +labels: + - "type: imperfection" +body: + - type: textarea + id: description + attributes: + label: Describe the problem + validations: + required: true + - type: textarea + id: reproduce + attributes: + label: To reproduce + description: Provide the specific set of steps we can follow to reproduce the problem. + validations: + required: true + - type: textarea + id: expected + attributes: + label: Expected behavior + description: What would you expect to happen after following those instructions? + validations: + required: true + - type: input + id: project-version + attributes: + label: The examples version + description: | + Which version of the "built-in examples" are you using? + _This should be the most recent version available._ + validations: + required: true + - type: textarea + id: additional + attributes: + label: Additional context + description: Add any additional information here. + validations: + required: false + - type: checkboxes + id: checklist + attributes: + label: Issue checklist + description: Please double-check that you have done each of the following things before submitting the issue. + options: + - label: I searched for previous reports in [the issue tracker](https://github.com/arduino/arduino-examples/issues?q=) + required: true + - label: I verified the problem still occurs when using the latest version + required: true + - label: My report contains all necessary details + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..cfceab5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,14 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/issue-templates/template-choosers/general/config.yml +# See: https://docs.github.com/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#configuring-the-template-chooser + +blank_issues_enabled: false +contact_links: + - name: Learn about using this project + url: https://github.com/arduino/arduino-examples#readme + about: Detailed usage documentation is available here. + - name: Support request + url: https://forum.arduino.cc/ + about: We can help you out on the Arduino Forum! + - name: Discuss development work on the project + url: https://groups.google.com/a/arduino.cc/g/developers + about: Arduino Developers Mailing List diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000..bd22292 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,51 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/issue-templates/forms/general/bug-report.yml +# See: https://docs.github.com/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms + +name: Feature request +description: Suggest an enhancement to this project. +labels: + - "type: enhancement" +body: + - type: textarea + id: description + attributes: + label: Describe the request + validations: + required: true + - type: textarea + id: current + attributes: + label: Describe the current behavior + description: | + What is the current behavior of the project in relation to your request? + How can we reproduce that behavior? + validations: + required: true + - type: input + id: project-version + attributes: + label: The examples version + description: | + Which version of the "built-in examples" are you using? + _This should be the most recent version available._ + validations: + required: true + - type: textarea + id: additional + attributes: + label: Additional context + description: Add any additional information here. + validations: + required: false + - type: checkboxes + id: checklist + attributes: + label: Issue checklist + description: Please double-check that you have done each of the following things before submitting the issue. + options: + - label: I searched for previous requests in [the issue tracker](https://github.com/arduino/arduino-examples/issues?q=) + required: true + - label: I verified the feature was still missing when using the latest version + required: true + - label: My request contains all necessary details + required: true diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..621d3f2 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +# See: https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#about-the-dependabotyml-file +version: 2 + +updates: + # Configure check for outdated GitHub Actions actions in workflows. + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/dependabot/README.md + # See: https://docs.github.com/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot + - package-ecosystem: github-actions + directory: / # Check the repository's workflows under /.github/workflows/ + assignees: + - per1234 + open-pull-requests-limit: 100 + schedule: + interval: daily + labels: + - "topic: infrastructure" diff --git a/.github/workflows/code-formatting-check.yml b/.github/workflows/code-formatting-check.yml index fe28659..bb3479f 100644 --- a/.github/workflows/code-formatting-check.yml +++ b/.github/workflows/code-formatting-check.yml @@ -4,10 +4,14 @@ on: pull_request: paths: - ".github/workflows/code-formatting-check.yml" + - ".clang-format" + - "examples_formatter.sh" - "examples/**" push: paths: - ".github/workflows/code-formatting-check.yml" + - ".clang-format" + - "examples_formatter.sh" - "examples/**" jobs: @@ -15,49 +19,43 @@ 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@v2 + uses: actions/checkout@v4 - # See: http://astyle.sourceforge.net/ - - name: Download Artistic Style - uses: carlosperate/download-file-action@v1.0.3 + - name: Download ClangFormat + id: download + uses: MrOctopus/download-asset-action@1.0 with: - file-url: https://iweb.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 - - # GITHUB_WORKSPACE - - name: Check code formatting + 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 "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH" + + - 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" diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 3e2e142..b184f9d 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -16,13 +16,25 @@ name: Compile Examples on: pull_request: - paths: - - ".github/workflows/compile-examples.yml" - - "examples/**" + paths-ignore: + - "**" + - "!.github/workflows/compile-examples.ya?ml" + - "!examples/**" + - "**.adoc" + - "**.jpg" + - "**.md" + - "**.png" + - "**.txt" push: - paths: - - ".github/workflows/compile-examples.yml" - - "examples/**" + paths-ignore: + - "**" + - "!.github/workflows/compile-examples.ya?ml" + - "!examples/**" + - "**.adoc" + - "**.jpg" + - "**.md" + - "**.png" + - "**.txt" # Scheduled trigger checks for breakage caused by changes to external resources (libraries, platforms) schedule: # run every Tuesday at 3 AM UTC @@ -36,6 +48,7 @@ on: jobs: build: + name: ${{ matrix.board.fqbn }} runs-on: ubuntu-latest env: @@ -46,30 +59,41 @@ jobs: - name: CapacitiveSensor # Sketch paths to compile (recursive) for all boards - UNIVERSAL_SKETCH_PATHS: >- - "examples/01.Basics" - "examples/02.Digital/BlinkWithoutDelay" - "examples/02.Digital/Button" - "examples/02.Digital/Debounce" - "examples/02.Digital/DigitalInputPullup" - "examples/02.Digital/StateChangeDetection" - "examples/03.Analog" - "examples/04.Communication/ASCIITable" - "examples/04.Communication/Dimmer" - "examples/04.Communication/Graph" - "examples/04.Communication/Midi" - "examples/04.Communication/PhysicalPixel" - "examples/04.Communication/ReadASCIIString" - "examples/04.Communication/SerialCallResponse" - "examples/04.Communication/SerialCallResponseASCII" - "examples/04.Communication/SerialEvent" - "examples/04.Communication/VirtualColorMixer" - "examples/05.Control" - "examples/06.Sensors/ADXL3xx" - "examples/06.Sensors/Knock" - "examples/07.Display" - "examples/08.Strings" - "examples/11.ArduinoISP" + UNIVERSAL_SKETCH_PATHS: | + - examples/01.Basics + - examples/02.Digital/BlinkWithoutDelay + - examples/02.Digital/Button + - examples/02.Digital/Debounce + - examples/02.Digital/DigitalInputPullup + - examples/02.Digital/StateChangeDetection + - examples/03.Analog + - examples/04.Communication/ASCIITable + - examples/04.Communication/Dimmer + - examples/04.Communication/Graph + - examples/04.Communication/Midi + - examples/04.Communication/PhysicalPixel + - examples/04.Communication/ReadASCIIString + - examples/04.Communication/SerialCallResponse + - examples/04.Communication/SerialCallResponseASCII + - examples/04.Communication/SerialEvent + - examples/04.Communication/VirtualColorMixer + - examples/05.Control + - examples/06.Sensors + - examples/07.Display + - examples/08.Strings/CharacterAnalysis + - examples/08.Strings/StringAdditionOperator + - examples/08.Strings/StringAppendOperator + - examples/08.Strings/StringCaseChanges + - examples/08.Strings/StringCharacters + - examples/08.Strings/StringConstructors + - examples/08.Strings/StringIndexOf + - examples/08.Strings/StringLength + - examples/08.Strings/StringLengthTrim + - examples/08.Strings/StringReplace + - examples/08.Strings/StringStartsWithEndsWith + - examples/08.Strings/StringSubstring + - examples/08.Strings/StringToInt + - examples/11.ArduinoISP strategy: fail-fast: false @@ -82,47 +106,81 @@ jobs: serial1: false starter-kit: true tone: true - pulsein: true + a5: true # Adding this in addition to the Uno because it has 1.5 kB less available flash - fqbn: arduino:avr:nano usb: false serial1: false starter-kit: false tone: true - pulsein: true + a5: true - fqbn: arduino:avr:leonardo usb: true serial1: true starter-kit: false tone: true - pulsein: true + a5: true + - fqbn: arduino:esp32:nano_nora + usb: false + serial1: true + starter-kit: false + tone: true + a5: true - fqbn: arduino:megaavr:uno2018:mode=off usb: false serial1: true starter-kit: false tone: true - pulsein: true + a5: true + - fqbn: arduino:renesas_uno:minima + usb: true + serial1: true + starter-kit: false + tone: true + a5: true + - fqbn: arduino:renesas_uno:unor4wifi + usb: true + serial1: true + starter-kit: false + tone: true + a5: true + - fqbn: arduino:renesas_portenta:portenta_c33 + usb: true + serial1: true + starter-kit: false + tone: true + a5: true - fqbn: arduino:samd:mkrzero usb: true serial1: true starter-kit: false tone: true - pulsein: true - - fqbn: arduino:mbed:nano33ble + a5: true + - fqbn: arduino:mbed_giga:giga usb: false serial1: true starter-kit: false tone: true - pulsein: true - # Change this to arduino:mbed:envie_m7 once there is a production release of the Arduino Mbed OS Boards platform - - fqbn: arduino-beta:mbed:envie_m7 + a5: true + - fqbn: arduino:mbed_nano:nano33ble usb: false serial1: true starter-kit: false tone: true - # Bug report: https://github.com/arduino/ArduinoCore-mbed/issues/48 - # Change the value to true once it is fixed. - pulsein: false + a5: true + - fqbn: arduino:mbed_nano:nanorp2040connect + usb: false + serial1: true + starter-kit: false + tone: true + # WiFiNINA library is required to use pins A4-A7. + a5: false + - fqbn: arduino:mbed_portenta:envie_m7 + usb: false + serial1: true + starter-kit: false + tone: true + a5: true - fqbn: arduino:sam:arduino_due_x usb: true serial1: true @@ -130,7 +188,7 @@ jobs: # Bug report: https://github.com/arduino/ArduinoCore-sam/issues/24 # Change the value to true once it is fixed. tone: false - pulsein: true + a5: true # Make board type-specific customizations to the matrix jobs include: @@ -142,8 +200,8 @@ jobs: - name: Keyboard - name: Mouse # Compile these sketches in addition to the ones defined by env.UNIVERSAL_SKETCH_PATHS - usb-sketch-paths: >- - "examples/09.USB" + usb-sketch-paths: | + - examples/09.USB - board: usb: false usb-libraries: "" @@ -151,55 +209,51 @@ jobs: - board: # Boards with a Serial1 port serial1: true - serial1-sketch-paths: >- - "examples/04.Communication/MultiSerial" - "examples/04.Communication/SerialPassthrough" + serial1-sketch-paths: | + - examples/04.Communication/MultiSerial + - examples/04.Communication/SerialPassthrough - board: serial1: false serial1-sketch-paths: "" - board: starter-kit: true - starter-kit-sketch-paths: >- - "examples/10.StarterKit_BasicKit" + starter-kit-sketch-paths: | + - examples/10.StarterKit_BasicKit - board: starter-kit: false starter-kit-sketch-paths: "" - board: tone: true - tone-sketch-paths: >- - "examples/02.Digital/toneKeyboard" - "examples/02.Digital/toneMelody" - "examples/02.Digital/toneMultiple" - "examples/02.Digital/tonePitchFollower" + tone-sketch-paths: | + - examples/02.Digital/toneKeyboard + - examples/02.Digital/toneMelody + - examples/02.Digital/toneMultiple + - examples/02.Digital/tonePitchFollower - board: tone: false tone-sketch-paths: "" - board: - pulsein: true - pulsein-sketch-paths: >- - "examples/06.Sensors/Memsic2125" - "examples/06.Sensors/Ping" + a5: true + a5-sketch-paths: | + - examples/08.Strings/StringComparisonOperators - board: - pulsein: false - pulsein-sketch-paths: "" + a5: false + tone-sketch-paths: "" steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Compile examples - uses: arduino/actions/libraries/compile-examples@master + uses: arduino/compile-sketches@v1 with: fqbn: ${{ matrix.board.fqbn }} libraries: | ${{ env.UNIVERSAL_LIBRARIES }} ${{ matrix.usb-libraries }} - sketch-paths: >- + sketch-paths: | ${{ env.UNIVERSAL_SKETCH_PATHS }} ${{ matrix.usb-sketch-paths }} ${{ matrix.serial1-sketch-paths }} ${{ matrix.starter-kit-sketch-paths }} ${{ matrix.tone-sketch-paths }} - ${{ matrix.pulsein-sketch-paths }} - # This input can be removed once the repository is made public - github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index b53bc44..a3af916 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md - name: Spell check diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml new file mode 100644 index 0000000..514f29a --- /dev/null +++ b/.github/workflows/sync-labels.yml @@ -0,0 +1,139 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md +name: Sync Labels + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + pull_request: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + schedule: + # Run daily at 8 AM UTC to sync with changes to shared label configurations. + - cron: "0 8 * * *" + workflow_dispatch: + repository_dispatch: + +env: + CONFIGURATIONS_FOLDER: .github/label-configuration-files + CONFIGURATIONS_ARTIFACT_PREFIX: label-configuration-file- + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download JSON schema for labels configuration file + id: download-schema + uses: carlosperate/download-file-action@v2 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json + location: ${{ runner.temp }}/label-configuration-schema + + - name: Install JSON schema validator + run: | + sudo npm install \ + --global \ + ajv-cli \ + ajv-formats + + - name: Validate local labels configuration + run: | + # See: https://github.com/ajv-validator/ajv-cli#readme + ajv validate \ + --all-errors \ + -c ajv-formats \ + -s "${{ steps.download-schema.outputs.file-path }}" \ + -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" + + download: + needs: check + runs-on: ubuntu-latest + + strategy: + matrix: + filename: + # Filenames of the shared configurations to apply to the repository in addition to the local configuration. + # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels + - universal.yml + + steps: + - name: Download + uses: carlosperate/download-file-action@v2 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} + + - name: Pass configuration files to next job via workflow artifact + uses: actions/upload-artifact@v4 + with: + path: | + *.yaml + *.yml + if-no-files-found: error + name: ${{ env.CONFIGURATIONS_ARTIFACT_PREFIX }}${{ matrix.filename }} + + sync: + needs: download + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" + + - name: Determine whether to dry run + id: dry-run + if: > + github.event_name == 'pull_request' || + ( + ( + github.event_name == 'push' || + github.event_name == 'workflow_dispatch' + ) && + github.ref != format('refs/heads/{0}', github.event.repository.default_branch) + ) + run: | + # Use of this flag in the github-label-sync command will cause it to only check the validity of the + # configuration. + echo "::set-output name=flag::--dry-run" + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download configuration file artifacts + uses: actions/download-artifact@v4 + with: + merge-multiple: true + pattern: ${{ env.CONFIGURATIONS_ARTIFACT_PREFIX }}* + path: ${{ env.CONFIGURATIONS_FOLDER }} + + - name: Remove unneeded artifacts + uses: geekyeggo/delete-artifact@v5 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT_PREFIX }}* + + - name: Merge label configuration files + run: | + # Merge all configuration files + shopt -s extglob + cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" + + - name: Install github-label-sync + run: sudo npm install --global github-label-sync + + - name: Sync labels + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # See: https://github.com/Financial-Times/github-label-sync + github-label-sync \ + --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ + ${{ steps.dry-run.outputs.flag }} \ + ${{ github.repository }} diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..0e259d4 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino b/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino index 789785d..b2da80c 100644 --- a/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino +++ b/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino @@ -7,7 +7,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/AnalogReadSerial + https://docs.arduino.cc/built-in-examples/basics/AnalogReadSerial/ */ // the setup routine runs once when you press reset: @@ -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 b737725..eb03a1e 100644 --- a/examples/01.Basics/Blink/Blink.ino +++ b/examples/01.Basics/Blink/Blink.ino @@ -8,7 +8,7 @@ the correct LED pin independent of which board is used. If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at: - https://www.arduino.cc/en/Main/Products + https://docs.arduino.cc/hardware/ modified 8 May 2014 by Scott Fitzgerald @@ -19,7 +19,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Blink + https://docs.arduino.cc/built-in-examples/basics/Blink/ */ // the setup function runs once when you press reset or power the board @@ -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 b3040af..170e083 100644 --- a/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino +++ b/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino @@ -5,7 +5,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/DigitalReadSerial + https://docs.arduino.cc/built-in-examples/basics/DigitalReadSerial/ */ // digital pin 2 has a pushbutton attached to it. Give it a name: @@ -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 744dc42..516d526 100644 --- a/examples/01.Basics/Fade/Fade.ino +++ b/examples/01.Basics/Fade/Fade.ino @@ -10,12 +10,12 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Fade + https://docs.arduino.cc/built-in-examples/basics/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/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino b/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino index 4473b4e..8e13468 100644 --- a/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino +++ b/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino @@ -7,7 +7,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage + https://docs.arduino.cc/built-in-examples/basics/ReadAnalogVoltage/ */ // the setup routine runs once when you press reset: diff --git a/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino b/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino index c96f3ba..63bebe2 100644 --- a/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino +++ b/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @@ -12,7 +12,7 @@ is set to the correct LED pin independent of which board is used. If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at: - https://www.arduino.cc/en/Main/Products + https://docs.arduino.cc/hardware/ created 2005 by David A. Mellis @@ -25,21 +25,21 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay + https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay/ */ // 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 06cb351..947f83f 100644 --- a/examples/02.Digital/Button/Button.ino +++ b/examples/02.Digital/Button/Button.ino @@ -5,7 +5,7 @@ when pressing a pushbutton attached to pin 2. The circuit: - - LED attached from pin 13 to ground + - LED attached from pin 13 to ground through 220 ohm resistor - pushbutton attached to pin 2 from +5V - 10K resistor attached to pin 2 from ground @@ -19,15 +19,15 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Button + https://docs.arduino.cc/built-in-examples/digital/Button/ */ // 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 d5d48c9..b091de4 100644 --- a/examples/02.Digital/Debounce/Debounce.ino +++ b/examples/02.Digital/Debounce/Debounce.ino @@ -6,7 +6,7 @@ minimum delay between toggles to debounce the circuit (i.e. to ignore noise). The circuit: - - LED attached from pin 13 to ground + - LED attached from pin 13 to ground through 220 ohm resistor - pushbutton attached from pin 2 to +5V - 10 kilohm resistor attached from pin 2 to ground @@ -24,17 +24,17 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Debounce + https://docs.arduino.cc/built-in-examples/digital/Debounce/ */ // 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 dc641ac..b81798d 100644 --- a/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino +++ b/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino @@ -17,7 +17,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/InputPullupSerial + https://docs.arduino.cc/built-in-examples/digital/InputPullupSerial/ */ void setup() { @@ -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 a5ba8da..37c23dd 100644 --- a/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino +++ b/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino @@ -12,8 +12,8 @@ The circuit: - pushbutton attached to pin 2 from +5V - 10 kilohm resistor attached to pin 2 from ground - - LED attached from pin 13 to ground (or use the built-in LED on most - Arduino boards) + - LED attached from pin 13 to ground through 220 ohm resistor (or use the + built-in LED on most Arduino boards) created 27 Sep 2005 modified 30 Aug 2011 @@ -21,17 +21,17 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/ButtonStateChange + https://docs.arduino.cc/built-in-examples/digital/StateChangeDetection/ */ // 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 7a958c9..1f1bf26 100644 --- a/examples/02.Digital/toneKeyboard/toneKeyboard.ino +++ b/examples/02.Digital/toneKeyboard/toneKeyboard.ino @@ -14,12 +14,12 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Tone3 + https://docs.arduino.cc/built-in-examples/digital/toneKeyboard/ */ #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/toneMelody/toneMelody.ino b/examples/02.Digital/toneMelody/toneMelody.ino index 8cc1b53..2e4614e 100644 --- a/examples/02.Digital/toneMelody/toneMelody.ino +++ b/examples/02.Digital/toneMelody/toneMelody.ino @@ -12,7 +12,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Tone + https://docs.arduino.cc/built-in-examples/digital/toneMelody/ */ #include "pitches.h" diff --git a/examples/02.Digital/toneMultiple/toneMultiple.ino b/examples/02.Digital/toneMultiple/toneMultiple.ino index f21f572..81e50d9 100644 --- a/examples/02.Digital/toneMultiple/toneMultiple.ino +++ b/examples/02.Digital/toneMultiple/toneMultiple.ino @@ -12,11 +12,10 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Tone4 + https://docs.arduino.cc/built-in-examples/digital/toneMultiple/ */ void setup() { - } void loop() { diff --git a/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino b/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino index c8d8567..260a172 100644 --- a/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino +++ b/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino @@ -14,7 +14,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Tone2 + https://docs.arduino.cc/built-in-examples/digital/tonePitchFollower/ */ void setup() { @@ -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 6675a8c..88aa312 100644 --- a/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino +++ b/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino @@ -9,7 +9,7 @@ - potentiometer connected to analog pin 0. Center pin of the potentiometer goes to the analog pin. side pins of the potentiometer go to +5V and ground - - LED connected from digital pin 9 to ground + - LED connected from digital pin 9 to ground through 220 ohm resistor created 29 Dec. 2008 modified 9 Apr 2012 @@ -17,15 +17,15 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/AnalogInOutSerial + https://docs.arduino.cc/built-in-examples/analog/AnalogInOutSerial/ */ // 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 13e7b52..e5e448c 100644 --- a/examples/03.Analog/AnalogInput/AnalogInput.ino +++ b/examples/03.Analog/AnalogInput/AnalogInput.ino @@ -12,7 +12,7 @@ one side pin (either one) to ground the other side pin to +5V - LED - anode (long leg) attached to digital output 13 + anode (long leg) attached to digital output 13 through 220 ohm resistor cathode (short leg) attached to ground - Note: because most Arduinos have a built-in LED attached to pin 13 on the @@ -24,10 +24,10 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/AnalogInput + https://docs.arduino.cc/built-in-examples/analog/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 @@ -45,6 +45,6 @@ void loop() { delay(sensorValue); // turn the ledPin off: digitalWrite(ledPin, LOW); - // stop the program for for milliseconds: + // stop the program for milliseconds: delay(sensorValue); } diff --git a/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino b/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino index 37a62a1..da14f13 100644 --- a/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino +++ b/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino @@ -12,7 +12,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/AnalogWriteMega + https://docs.arduino.cc/built-in-examples/analog/AnalogWriteMega/ */ // These constants won't change. They're used to give names to the pins used: diff --git a/examples/03.Analog/Calibration/Calibration.ino b/examples/03.Analog/Calibration/Calibration.ino index 5c0fc6d..17cc790 100644 --- a/examples/03.Analog/Calibration/Calibration.ino +++ b/examples/03.Analog/Calibration/Calibration.ino @@ -12,26 +12,28 @@ The circuit: - analog sensor (potentiometer will do) attached to analog input 0 - - LED attached from digital pin 9 to ground + - LED attached from digital pin 9 to ground through 220 ohm resistor created 29 Oct 2008 by David A Mellis modified 30 Aug 2011 by Tom Igoe + modified 07 Apr 2017 + by Zachary J. Fields This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Calibration + https://docs.arduino.cc/built-in-examples/analog/Calibration/ */ // 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() { @@ -62,12 +64,12 @@ void loop() { // read the sensor: sensorValue = analogRead(sensorPin); + // in case the sensor value is outside the range seen during calibration + sensorValue = constrain(sensorValue, sensorMin, sensorMax); + // apply the calibration to the sensor reading sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); - // in case the sensor value is outside the range seen during calibration - sensorValue = constrain(sensorValue, 0, 255); - // fade the LED using the calibrated value: analogWrite(ledPin, sensorValue); } diff --git a/examples/03.Analog/Fading/Fading.ino b/examples/03.Analog/Fading/Fading.ino index 1612b8b..b7f42f1 100644 --- a/examples/03.Analog/Fading/Fading.ino +++ b/examples/03.Analog/Fading/Fading.ino @@ -4,7 +4,7 @@ This example shows how to fade an LED using the analogWrite() function. The circuit: - - LED attached from digital pin 9 to ground. + - LED attached from digital pin 9 to ground through 220 ohm resistor. created 1 Nov 2008 by David A. Mellis @@ -13,10 +13,10 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Fading + https://docs.arduino.cc/built-in-examples/analog/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 5df0d05..2b26d56 100644 --- a/examples/03.Analog/Smoothing/Smoothing.ino +++ b/examples/03.Analog/Smoothing/Smoothing.ino @@ -15,7 +15,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Smoothing + https://docs.arduino.cc/built-in-examples/analog/Smoothing/ */ // Define the number of samples to keep track of. The higher the number, the @@ -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 7cf55d0..2f6e2fa 100644 --- a/examples/04.Communication/ASCIITable/ASCIITable.ino +++ b/examples/04.Communication/ASCIITable/ASCIITable.ino @@ -16,14 +16,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/ASCIITable + https://docs.arduino.cc/built-in-examples/communication/ASCIITable/ */ 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 39be765..e6475c3 100644 --- a/examples/04.Communication/Dimmer/Dimmer.ino +++ b/examples/04.Communication/Dimmer/Dimmer.ino @@ -7,7 +7,7 @@ set the brightness of the LED. The circuit: - - LED attached from digital pin 9 to ground. + - LED attached from digital pin 9 to ground through 220 ohm resistor. - Serial connection to Processing, Max/MSP, or another serial application created 2006 @@ -17,10 +17,10 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Dimmer + https://docs.arduino.cc/built-in-examples/communication/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/Graph/Graph.ino b/examples/04.Communication/Graph/Graph.ino index 8be36d2..0fd33b2 100644 --- a/examples/04.Communication/Graph/Graph.ino +++ b/examples/04.Communication/Graph/Graph.ino @@ -22,7 +22,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Graph + https://docs.arduino.cc/built-in-examples/communication/Graph/ */ void setup() { diff --git a/examples/04.Communication/Midi/Midi.ino b/examples/04.Communication/Midi/Midi.ino index 5ef3406..901766d 100644 --- a/examples/04.Communication/Midi/Midi.ino +++ b/examples/04.Communication/Midi/Midi.ino @@ -17,7 +17,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Midi + https://docs.arduino.cc/built-in-examples/communication/Midi/ */ void setup() { @@ -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/MultiSerial/MultiSerial.ino b/examples/04.Communication/MultiSerial/MultiSerial.ino index d356f51..30f7dd0 100644 --- a/examples/04.Communication/MultiSerial/MultiSerial.ino +++ b/examples/04.Communication/MultiSerial/MultiSerial.ino @@ -17,6 +17,8 @@ by Arturo Guadalupi This example code is in the public domain. + + https://docs.arduino.cc/built-in-examples/communication/MultiSerialMega/ */ diff --git a/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino b/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino index cf35cd2..ff8866e 100644 --- a/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino +++ b/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino @@ -9,7 +9,7 @@ Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. The circuit: - - LED connected from digital pin 13 to ground + - LED connected from digital pin 13 to ground through 220 ohm resistor created 2006 by David A. Mellis @@ -18,11 +18,11 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/PhysicalPixel + https://docs.arduino.cc/built-in-examples/communication/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 ab26c28..4832d6b 100644 --- a/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino +++ b/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino @@ -6,9 +6,9 @@ It parses them into ints, and uses those to fade an RGB LED. Circuit: Common-Cathode RGB LED wired like so: - - red anode: digital pin 3 - - green anode: digital pin 5 - - blue anode: digital pin 6 + - red anode: digital pin 3 through 220 ohm resistor + - green anode: digital pin 5 through 220 ohm resistor + - blue anode: digital pin 6 through 220 ohm resistor - cathode: GND created 13 Apr 2012 @@ -17,6 +17,8 @@ by Arturo Guadalupi This example code is in the public domain. + + https://docs.arduino.cc/built-in-examples/communication/ReadASCIIString/ */ // pins for the LEDs: @@ -31,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 b59204f..9983cd4 100644 --- a/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino +++ b/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino @@ -18,19 +18,19 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/SerialCallResponse + https://docs.arduino.cc/built-in-examples/communication/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 f14206c..ee044c6 100644 --- a/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino +++ b/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -19,19 +19,19 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII + https://docs.arduino.cc/built-in-examples/communication/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 1ec4049..2401a63 100644 --- a/examples/04.Communication/SerialEvent/SerialEvent.ino +++ b/examples/04.Communication/SerialEvent/SerialEvent.ino @@ -15,10 +15,10 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/SerialEvent + https://docs.arduino.cc/built-in-examples/communication/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 81037eb..96fc01a 100644 --- a/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino +++ b/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino @@ -20,6 +20,8 @@ created 23 May 2016 by Erik Nyquist + + https://docs.arduino.cc/built-in-examples/communication/SerialPassthrough/ */ void setup() { @@ -28,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 d674d59..54ad16b 100644 --- a/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino +++ b/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino @@ -13,12 +13,12 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/VirtualColorMixer + https://docs.arduino.cc/built-in-examples/communication/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 549ac34..cefc940 100644 --- a/examples/05.Control/Arrays/Arrays.ino +++ b/examples/05.Control/Arrays/Arrays.ino @@ -17,14 +17,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Array + https://docs.arduino.cc/built-in-examples/control-structures/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 54ad38a..8e3f3cd 100644 --- a/examples/05.Control/ForLoopIteration/ForLoopIteration.ino +++ b/examples/05.Control/ForLoopIteration/ForLoopIteration.ino @@ -14,10 +14,10 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/ForLoop + https://docs.arduino.cc/built-in-examples/control-structures/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 4dd4090..d57caa7 100644 --- a/examples/05.Control/IfStatementConditional/IfStatementConditional.ino +++ b/examples/05.Control/IfStatementConditional/IfStatementConditional.ino @@ -10,7 +10,7 @@ - potentiometer Center pin of the potentiometer goes to analog pin 0. Side pins of the potentiometer go to +5V and ground. - - LED connected from digital pin 13 to ground + - LED connected from digital pin 13 to ground through 220 ohm resistor - Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example. @@ -21,13 +21,13 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/IfStatement + https://docs.arduino.cc/built-in-examples/control-structures/ifStatementConditional/ */ // 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 4f1383f..d7955d0 100644 --- a/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino +++ b/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino @@ -24,21 +24,21 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/WhileLoop + https://docs.arduino.cc/built-in-examples/control-structures/WhileStatementConditional/ */ // 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 c313f6b..c2b736b 100644 --- a/examples/05.Control/switchCase/switchCase.ino +++ b/examples/05.Control/switchCase/switchCase.ino @@ -18,13 +18,13 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/SwitchCase + https://docs.arduino.cc/built-in-examples/control-structures/SwitchCase/ */ // 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/05.Control/switchCase2/switchCase2.ino b/examples/05.Control/switchCase2/switchCase2.ino index c30843f..554f3ac 100644 --- a/examples/05.Control/switchCase2/switchCase2.ino +++ b/examples/05.Control/switchCase2/switchCase2.ino @@ -17,7 +17,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/SwitchCase2 + https://docs.arduino.cc/built-in-examples/control-structures/SwitchCase2/ */ void setup() { diff --git a/examples/06.Sensors/ADXL3xx/ADXL3xx.ino b/examples/06.Sensors/ADXL3xx/ADXL3xx.ino index 1cf4be4..30282d0 100644 --- a/examples/06.Sensors/ADXL3xx/ADXL3xx.ino +++ b/examples/06.Sensors/ADXL3xx/ADXL3xx.ino @@ -4,7 +4,7 @@ Reads an Analog Devices ADXL3xx accelerometer and communicates the acceleration to the computer. The pins used are designed to be easily compatible with the breakout boards from SparkFun, available from: - http://www.sparkfun.com/commerce/categories.php?c=80 + https://www.sparkfun.com/categories/80 The circuit: - analog 0: accelerometer self test @@ -21,15 +21,15 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/ADXL3xx + https://docs.arduino.cc/built-in-examples/sensors/ADXL3xx/ */ // 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 99b50e4..46047d9 100644 --- a/examples/06.Sensors/Knock/Knock.ino +++ b/examples/06.Sensors/Knock/Knock.ino @@ -18,22 +18,22 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Knock + https://docs.arduino.cc/built-in-examples/sensors/Knock/ */ // 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 } @@ -49,6 +49,6 @@ void loop() { digitalWrite(ledPin, ledState); // send the string "Knock!" back to the computer, followed by newline Serial.println("Knock!"); + delay(100); // delay to avoid overloading the serial port buffer } - delay(100); // delay to avoid overloading the serial port buffer } diff --git a/examples/06.Sensors/Memsic2125/Memsic2125.ino b/examples/06.Sensors/Memsic2125/Memsic2125.ino index da69df9..a6aea27 100644 --- a/examples/06.Sensors/Memsic2125/Memsic2125.ino +++ b/examples/06.Sensors/Memsic2125/Memsic2125.ino @@ -18,12 +18,12 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Memsic2125 + https://docs.arduino.cc/built-in-examples/sensors/Memsic2125/ */ // 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/06.Sensors/Ping/Ping.ino b/examples/06.Sensors/Ping/Ping.ino index cdde18e..a217ba2 100644 --- a/examples/06.Sensors/Ping/Ping.ino +++ b/examples/06.Sensors/Ping/Ping.ino @@ -18,7 +18,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/Ping + https://docs.arduino.cc/built-in-examples/sensors/Ping/ */ // this constant won't change. It's the pin number of the sensor's output: @@ -67,7 +67,7 @@ long microsecondsToInches(long microseconds) { // microseconds per inch (i.e. sound travels at 1130 feet per second). // This gives the distance travelled by the ping, outbound and return, // so we divide by 2 to get the distance of the obstacle. - // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf + // See: https://www.parallax.com/package/ping-ultrasonic-distance-sensor-downloads/ return microseconds / 74 / 2; } diff --git a/examples/07.Display/RowColumnScanning/RowColumnScanning.ino b/examples/07.Display/RowColumnScanning/RowColumnScanning.ino index f2cf795..54a1224 100644 --- a/examples/07.Display/RowColumnScanning/RowColumnScanning.ino +++ b/examples/07.Display/RowColumnScanning/RowColumnScanning.ino @@ -4,7 +4,7 @@ This example controls an 8x8 LED matrix using two analog inputs. This example works for the Lumex LDM-24488NI Matrix. See - http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf + https://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf for the pin connections. For other LED cathode column matrixes, you should only need to change the pin @@ -28,9 +28,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/RowColumnScanning - - see also http://www.tigoe.net/pcomp/code/category/arduinowiring for more + https://docs.arduino.cc/built-in-examples/display/RowColumnScanning/ */ // 2-dimensional array of row pin numbers: @@ -85,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 48327a9..cd5a16c 100644 --- a/examples/07.Display/barGraph/barGraph.ino +++ b/examples/07.Display/barGraph/barGraph.ino @@ -17,16 +17,16 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/BarGraph + https://docs.arduino.cc/built-in-examples/display/BarGraph/ */ // 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 07a89c5..9f338e6 100644 --- a/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino +++ b/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -10,14 +10,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/CharacterAnalysis + https://docs.arduino.cc/built-in-examples/strings/CharacterAnalysis/ */ 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 5f65e50..d85aa44 100644 --- a/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino +++ b/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -10,7 +10,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringAdditionOperator + https://docs.arduino.cc/built-in-examples/strings/StringAdditionOperator/ */ // declare three Strings: @@ -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 abdfe76..d7bc959 100644 --- a/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino +++ b/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino @@ -9,7 +9,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringAppendOperator + https://docs.arduino.cc/built-in-examples/strings/StringAppendOperator/ */ String stringOne, stringTwo; @@ -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 78a1270..0d983f2 100644 --- a/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino +++ b/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino @@ -9,14 +9,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringCaseChanges + https://docs.arduino.cc/built-in-examples/strings/StringCaseChanges/ */ 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 f985e79..93f2a16 100644 --- a/examples/08.Strings/StringCharacters/StringCharacters.ino +++ b/examples/08.Strings/StringCharacters/StringCharacters.ino @@ -9,14 +9,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringCharacters + https://docs.arduino.cc/built-in-examples/strings/StringCharacters/ */ 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 48540f9..f8c9d80 100644 --- a/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino +++ b/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -9,7 +9,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringComparisonOperators + https://docs.arduino.cc/built-in-examples/strings/StringComparisonOperators/ */ String stringOne, stringTwo; @@ -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 414dd8d..146674a 100644 --- a/examples/08.Strings/StringConstructors/StringConstructors.ino +++ b/examples/08.Strings/StringConstructors/StringConstructors.ino @@ -9,14 +9,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringConstructors + https://docs.arduino.cc/built-in-examples/strings/StringConstructors/ */ 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 bac9f81..4741bdf 100644 --- a/examples/08.Strings/StringIndexOf/StringIndexOf.ino +++ b/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -9,14 +9,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringIndexOf + https://docs.arduino.cc/built-in-examples/strings/StringIndexOf/ */ 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 0fe5203..7732aa9 100644 --- a/examples/08.Strings/StringLength/StringLength.ino +++ b/examples/08.Strings/StringLength/StringLength.ino @@ -9,17 +9,17 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringLengthTrim + https://docs.arduino.cc/built-in-examples/strings/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 d107c8f..dbdf6b6 100644 --- a/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino +++ b/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -9,14 +9,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringLengthTrim + https://docs.arduino.cc/built-in-examples/strings/StringLengthTrim/ */ 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 17407f1..72bbb5e 100644 --- a/examples/08.Strings/StringReplace/StringReplace.ino +++ b/examples/08.Strings/StringReplace/StringReplace.ino @@ -9,14 +9,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringReplace + https://docs.arduino.cc/built-in-examples/strings/StringReplace/ */ 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 6ea6f2c..ef31a68 100644 --- a/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino +++ b/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino @@ -9,14 +9,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringStartsWithEndsWith + https://docs.arduino.cc/built-in-examples/strings/StringStartsWithEndsWith/ */ 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 ccdf2f3..0083212 100644 --- a/examples/08.Strings/StringSubstring/StringSubstring.ino +++ b/examples/08.Strings/StringSubstring/StringSubstring.ino @@ -9,14 +9,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringSubstring + https://docs.arduino.cc/built-in-examples/strings/StringSubstring/ */ 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 59e872a..c59a851 100644 --- a/examples/08.Strings/StringToInt/StringToInt.ino +++ b/examples/08.Strings/StringToInt/StringToInt.ino @@ -12,16 +12,16 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/StringToInt + https://docs.arduino.cc/built-in-examples/strings/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 f6ea490..e5a2572 100644 --- a/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino +++ b/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino @@ -22,7 +22,7 @@ This example is in the public domain. - http://www.arduino.cc/en/Tutorial/KeyboardLogout + https://docs.arduino.cc/built-in-examples/usb/KeyboardLogout/ */ #define OSX 0 @@ -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 32c3b9f..02ca922 100644 --- a/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino +++ b/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -17,14 +17,14 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/KeyboardMessage + https://docs.arduino.cc/built-in-examples/usb/KeyboardMessage/ */ #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 7ec0d6d..f6ae5f3 100644 --- a/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino +++ b/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -22,7 +22,7 @@ This example is in the public domain. - http://www.arduino.cc/en/Tutorial/KeyboardReprogram + https://docs.arduino.cc/built-in-examples/usb/KeyboardReprogram/ */ #include "Keyboard.h" @@ -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/Keyboard/KeyboardSerial/KeyboardSerial.ino b/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino index 72d9ddd..db5fb3d 100644 --- a/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino +++ b/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino @@ -16,7 +16,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/KeyboardSerial + https://docs.arduino.cc/built-in-examples/usb/KeyboardSerial/ */ #include "Keyboard.h" diff --git a/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino b/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino index 9713541..ffe82ac 100644 --- a/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino +++ b/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino @@ -18,7 +18,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/KeyboardAndMouseControl + https://docs.arduino.cc/built-in-examples/usb/KeyboardAndMouseControl/ */ #include "Keyboard.h" @@ -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 9c78eda..6eb0e4d 100644 --- a/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino +++ b/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino @@ -20,7 +20,7 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/ButtonMouseControl + https://docs.arduino.cc/built-in-examples/usb/ButtonMouseControl/ */ #include "Mouse.h" @@ -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 aa608f8..13e170c 100644 --- a/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino +++ b/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino @@ -26,30 +26,30 @@ This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/JoystickMouseControl + https://docs.arduino.cc/built-in-examples/usb/JoystickMouseControl/ */ #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 41283da..255d100 100644 --- a/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino +++ b/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino @@ -14,7 +14,7 @@ created 13 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ @@ -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 2a72f46..e8390a3 100644 --- a/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino +++ b/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino @@ -12,7 +12,7 @@ created 13 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ @@ -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 1e15f1c..8efc411 100644 --- a/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino +++ b/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino @@ -16,26 +16,26 @@ by Scott Fitzgerald Thanks to Federico Vanzati for improvements - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit 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 b56e860..5e2ccf3 100644 --- a/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino +++ b/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino @@ -12,7 +12,7 @@ created 13 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ @@ -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/p06_LightTheremin/p06_LightTheremin.ino b/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino index 6f6475c..1b79405 100644 --- a/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino +++ b/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino @@ -12,7 +12,7 @@ created 13 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ diff --git a/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino b/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino index ad39bd1..f6b6fb3 100644 --- a/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino +++ b/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino @@ -14,14 +14,14 @@ created 13 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ // 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 801f8cd..3122c67 100644 --- a/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino +++ b/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino @@ -10,10 +10,13 @@ - six LEDs - tilt switch + NOTE: This sketch is intentionally incomplete. Make sure to add your own code + for whatever you want to happen at the end of the hour. + created 13 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ @@ -21,13 +24,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 @@ -55,6 +58,7 @@ void loop() { if (led == 7) { // the hour is up + // add your indicator code here } } diff --git a/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino b/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino index 23e19b1..8841d32 100644 --- a/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino +++ b/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino @@ -15,14 +15,14 @@ created 13 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ // 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 4d675ed..9b9991f 100644 --- a/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino +++ b/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino @@ -16,27 +16,27 @@ by Scott Fitzgerald Thanks to Federico Vanzati for improvements - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit 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/p11_CrystalBall/p11_CrystalBall.ino b/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino index 63aefc4..a5a6acb 100644 --- a/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino +++ b/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino @@ -14,7 +14,7 @@ created 13 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ diff --git a/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino b/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino index 95027ec..6401ac9 100644 --- a/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino +++ b/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino @@ -20,7 +20,7 @@ by Scott Fitzgerald Thanks to Federico Vanzati for improvements - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ @@ -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/p13_TouchSensorLamp/p13_TouchSensorLamp.ino b/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino index 8f7a28a..4f25cbe 100644 --- a/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino +++ b/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino @@ -12,12 +12,12 @@ Software required : - CapacitiveSensor library by Paul Badger - http://www.arduino.cc/playground/Main/CapacitiveSensor + https://www.arduino.cc/reference/en/libraries/capacitivesensor/ created 18 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ diff --git a/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino b/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino index e9279e2..043b600 100644 --- a/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino +++ b/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino @@ -8,13 +8,13 @@ - 10 kilohm potentiometer Software required: - - Processing (3.0 or newer) http://processing.org + - Processing (3.0 or newer) https://processing.org/ - Active Internet connection created 18 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit This example code is part of the public domain. */ diff --git a/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino b/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino index d5d530a..9db4bbf 100644 --- a/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino +++ b/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino @@ -12,12 +12,12 @@ created 18 Sep 2012 by Scott Fitzgerald - http://www.arduino.cc/starterKit + https://store.arduino.cc/genuino-starter-kit 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 43a91d3..6ceb85f 100644 --- a/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -1,7 +1,11 @@ // ArduinoISP // Copyright (c) 2008-2011 Randall Bohn // If you require a license, see -// http://www.opensource.org/licenses/bsd-license.php +// https://opensource.org/licenses/bsd-license.php +// +// Note that this sketch refers to the SPI bus pins using the legacy MISO/MOSI +// names rather than the modern CIPO/COPI names. +// For further details, see https://docs.arduino.cc/learn/communication/spi // // This sketch turns the Arduino into a AVRISP using the following Arduino pins: // @@ -22,8 +26,8 @@ // using an Uno. (On an Uno this is not needed). // // Alternatively you can use any other digital pin by configuring -// software ('BitBanged') SPI and having appropriate defines for PIN_MOSI, -// PIN_MISO and PIN_SCK. +// software ('BitBanged') SPI and having appropriate defines for ARDUINOISP_PIN_MOSI, +// ARDUINOISP_PIN_MISO and ARDUINOISP_PIN_SCK. // // IMPORTANT: When using an Arduino that is not 5V tolerant (Due, Zero, ...) as // the programmer, make sure to not expose any of the programmer's pins to 5V. @@ -33,7 +37,7 @@ // Put an LED (with resistor) on the following pins: // 9: Heartbeat - shows the programmer is running // 8: Error - Lights up if something goes wrong (use red if that makes sense) -// 7: Programming - In communication with the slave +// 7: Programming - In communication with the target // #include "Arduino.h" @@ -50,7 +54,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 +63,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 +74,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 ARDUINOISP_PIN_MOSI 11 +#define ARDUINOISP_PIN_MISO 12 +#define ARDUINOISP_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 +#ifndef ARDUINOISP_PIN_MOSI +#define ARDUINOISP_PIN_MOSI MOSI #endif -#ifndef PIN_MISO - #define PIN_MISO MISO +#ifndef ARDUINOISP_PIN_MISO +#define ARDUINOISP_PIN_MISO MISO #endif -#ifndef PIN_SCK - #define PIN_SCK SCK +#ifndef ARDUINOISP_PIN_SCK +#define ARDUINOISP_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 (ARDUINOISP_PIN_MISO != MISO) || (ARDUINOISP_PIN_MOSI != MOSI) || (ARDUINOISP_PIN_SCK != SCK) +#undef USE_HARDWARE_SPI #endif @@ -131,15 +135,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 +153,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 +168,58 @@ void pulse(int pin, int times); #define SPI_MODE0 0x00 -#if !defined(ARDUINO_API_VERSION) // A SPISettings class is declared by ArduinoCore-API +#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(ARDUINOISP_PIN_SCK, LOW); + digitalWrite(ARDUINOISP_PIN_MOSI, LOW); + pinMode(ARDUINOISP_PIN_SCK, OUTPUT); + pinMode(ARDUINOISP_PIN_MOSI, OUTPUT); + pinMode(ARDUINOISP_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(ARDUINOISP_PIN_MOSI, (b & 0x80) ? HIGH : LOW); + digitalWrite(ARDUINOISP_PIN_SCK, HIGH); + delayMicroseconds(pulseWidth); + b = (b << 1) | digitalRead(ARDUINOISP_PIN_MISO); + digitalWrite(ARDUINOISP_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 +235,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 +258,7 @@ typedef struct param { uint16_t pagesize; uint16_t eepromsize; uint32_t flashsize; -} -parameter; +} parameter; parameter param; @@ -307,7 +310,8 @@ void loop(void) { } uint8_t getch() { - while (!SERIAL.available()); + while (!SERIAL.available()) + ; return SERIAL.read(); } void fill(int n) { @@ -372,7 +376,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 +386,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) @@ -408,7 +412,7 @@ void set_parameters() { void start_pmode() { - // Reset target before driving PIN_SCK or PIN_MOSI + // Reset target before driving ARDUINOISP_PIN_SCK or ARDUINOISP_PIN_MOSI // SPI.begin() will configure SS as output, so SPI master mode is selected. // We have defined RESET as pin 10, which for many Arduinos is not the SS pin. @@ -421,9 +425,9 @@ void start_pmode() { // See AVR datasheets, chapter "SERIAL_PRG Programming Algorithm": - // Pulse RESET after PIN_SCK is low: - digitalWrite(PIN_SCK, LOW); - delay(20); // discharge PIN_SCK, value arbitrarily chosen + // Pulse RESET after ARDUINOISP_PIN_SCK is low: + digitalWrite(ARDUINOISP_PIN_SCK, LOW); + delay(20); // discharge ARDUINOISP_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 +435,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; } @@ -439,8 +443,8 @@ void start_pmode() { void end_pmode() { SPI.end(); // We're about to take the target out of reset so configure SPI pins as input - pinMode(PIN_MOSI, INPUT); - pinMode(PIN_SCK, INPUT); + pinMode(ARDUINOISP_PIN_MOSI, INPUT); + pinMode(ARDUINOISP_PIN_SCK, INPUT); reset_target(false); pinMode(RESET, INPUT); pmode = 0; @@ -491,11 +495,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 +553,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 +565,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 +587,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 +601,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 +613,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 +629,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 +650,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 +672,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 +682,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 +723,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 b331e55..23ecfe8 100755 --- a/examples_formatter.sh +++ b/examples_formatter.sh @@ -1,2 +1,22 @@ -# 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 {} \; +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 + +find \ + examples \ + \( \ + -name '*.c' -or \ + -name '*.cpp' -or \ + -name '*.h' -or \ + -name '*.ino' -or \ + -name '*.ipp' -or \ + -name '*.tpp' \ + \) \ + -type f \ + -exec \ + clang-format \ + --assume-filename=foo.cpp \ + -i \ + --style=file \ + {} \;