From 222440ccbcbb041898f74270aa71d26eab9f6ded Mon Sep 17 00:00:00 2001 From: clawpi Date: Tue, 17 Feb 2026 14:57:35 -0500 Subject: [PATCH 1/2] Run clang-format Co-authored-by: ladyada --- .clang-format | 239 ++++++++++++++++++ .../adafruitio_00_publish.ino | 7 +- .../adafruitio_01_subscribe.ino | 8 +- .../adafruitio_02_pubsub.ino | 8 +- .../adafruitio_03_multiple_feeds.ino | 15 +- .../adafruitio_04_location.ino | 8 +- .../adafruitio_05_type_conversion.ino | 28 +- .../adafruitio_06_digital_in.ino | 11 +- .../adafruitio_07_digital_out.ino | 14 +- .../adafruitio_08_analog_in.ino | 8 +- .../adafruitio_09_analog_out.ino | 33 ++- .../adafruitio_10_dashboard_creation.ino | 18 +- .../adafruitio_11_group_pub.ino | 6 +- .../adafruitio_12_group_sub.ino | 10 +- .../adafruitio_13_rgb/adafruitio_13_rgb.ino | 62 +++-- .../adafruitio_14_neopixel.ino | 19 +- .../adafruitio_15_temp_humidity.ino | 10 +- .../adafruitio_16_servo.ino | 20 +- .../adafruitio_17_time_subscribe.ino | 10 +- .../adafruitio_18_device_info.ino | 15 +- .../adafruitio_19_deepsleep.ino | 29 +-- .../adafruitio_20_shared_feed_write.ino | 16 +- .../adafruitio_21_feed_read.ino | 13 +- .../adafruitio_22_environmental_monitor.ino | 87 ++++--- .../adafruitio_23_ifttt.ino | 15 +- .../adafruitio_24_zapier.ino | 93 +++---- .../adafruitio_25_schedule_trigger.ino | 24 +- .../adafruitio_26_led_btn.ino | 16 +- .../adafruitio_27_wifimanager.ino | 33 +-- ...o_28_wifimanager-custom-aio-parameters.ino | 99 ++++---- .../io_home_security/io_home_security.ino | 129 +++++----- .../neopixel_and_thermometer.ino | 43 ++-- src/AdafruitIO_Definitions.h | 28 +- 33 files changed, 690 insertions(+), 484 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..e1b53a0b --- /dev/null +++ b/.clang-format @@ -0,0 +1,239 @@ +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +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: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE diff --git a/examples/adafruitio_00_publish/adafruitio_00_publish.ino b/examples/adafruitio_00_publish/adafruitio_00_publish.ino index 37f45c1b..3ef6a09f 100644 --- a/examples/adafruitio_00_publish/adafruitio_00_publish.ino +++ b/examples/adafruitio_00_publish/adafruitio_00_publish.ino @@ -31,7 +31,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -39,7 +40,7 @@ void setup() { io.connect(); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -47,7 +48,6 @@ void setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - } void loop() { @@ -70,5 +70,4 @@ void loop() { // between feed->save events. In this example, we will wait three seconds // (1000 milliseconds == 1 second) during each loop. delay(3000); - } diff --git a/examples/adafruitio_01_subscribe/adafruitio_01_subscribe.ino b/examples/adafruitio_01_subscribe/adafruitio_01_subscribe.ino index 1f4eb089..0b844302 100644 --- a/examples/adafruitio_01_subscribe/adafruitio_01_subscribe.ino +++ b/examples/adafruitio_01_subscribe/adafruitio_01_subscribe.ino @@ -28,7 +28,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -44,7 +45,7 @@ void setup() { // wait for an MQTT connection // NOTE: when blending the HTTP and MQTT API, always use the mqttStatus // method to check on MQTT connection status specifically - while(io.mqttStatus() < AIO_CONNECTED) { + while (io.mqttStatus() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -57,7 +58,6 @@ void setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - } void loop() { @@ -70,7 +70,6 @@ void loop() { // Because this sketch isn't publishing, we don't need // a delay() in the main program loop. - } // this function is called whenever a 'counter' message @@ -80,5 +79,4 @@ void handleMessage(AdafruitIO_Data *data) { Serial.print("received <- "); Serial.println(data->value()); - } diff --git a/examples/adafruitio_02_pubsub/adafruitio_02_pubsub.ino b/examples/adafruitio_02_pubsub/adafruitio_02_pubsub.ino index e268a118..1d5f0c99 100644 --- a/examples/adafruitio_02_pubsub/adafruitio_02_pubsub.ino +++ b/examples/adafruitio_02_pubsub/adafruitio_02_pubsub.ino @@ -44,7 +44,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -58,7 +59,7 @@ void setup() { counter->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -67,7 +68,6 @@ void setup() { Serial.println(); Serial.println(io.statusText()); counter->get(); - } void loop() { @@ -90,7 +90,6 @@ void loop() { // after publishing, store the current time lastUpdate = millis(); } - } // this function is called whenever a 'counter' message @@ -100,5 +99,4 @@ void handleMessage(AdafruitIO_Data *data) { Serial.print("received <- "); Serial.println(data->value()); - } diff --git a/examples/adafruitio_03_multiple_feeds/adafruitio_03_multiple_feeds.ino b/examples/adafruitio_03_multiple_feeds/adafruitio_03_multiple_feeds.ino index 1aa68ed8..f461b0ba 100644 --- a/examples/adafruitio_03_multiple_feeds/adafruitio_03_multiple_feeds.ino +++ b/examples/adafruitio_03_multiple_feeds/adafruitio_03_multiple_feeds.ino @@ -44,7 +44,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -61,7 +62,7 @@ void setup() { light->onMessage(handleLight); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -74,7 +75,6 @@ void setup() { counter->get(); counter_two->get(); light->get(); - } void loop() { @@ -97,7 +97,7 @@ void loop() { // print out the light value we are sending to Adafruit IO Serial.print("sending -> light "); - if(is_on) + if (is_on) Serial.println("is on.\n"); else Serial.println("is off.\n"); @@ -110,7 +110,7 @@ void loop() { // for the purpose of this demo, toggle the // light state based on the count value - if((count % 2) == 0) + if ((count % 2) == 0) is_on = true; else is_on = false; @@ -118,7 +118,6 @@ void loop() { // update timer lastUpdate = millis(); } - } // you can set a separate message handler for a single feed, @@ -130,11 +129,10 @@ void handleLight(AdafruitIO_Data *data) { // use the isTrue helper to get the // boolean state of the light - if(data->isTrue()) + if (data->isTrue()) Serial.println("is on."); else Serial.println("is off."); - } // you can also attach multiple feeds to the same @@ -153,5 +151,4 @@ void handleCount(AdafruitIO_Data *data) { // print out the received count or counter-two value Serial.println(data->value()); - } diff --git a/examples/adafruitio_04_location/adafruitio_04_location.ino b/examples/adafruitio_04_location/adafruitio_04_location.ino index 8cae103e..dc6d61ad 100644 --- a/examples/adafruitio_04_location/adafruitio_04_location.ino +++ b/examples/adafruitio_04_location/adafruitio_04_location.ino @@ -41,7 +41,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -52,7 +53,7 @@ void setup() { location->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -61,7 +62,6 @@ void setup() { Serial.println(); Serial.println(io.statusText()); location->get(); - } void loop() { @@ -93,7 +93,6 @@ void loop() { // wait one second (1000 milliseconds == 1 second) lastUpdate = millis(); } - } void handleMessage(AdafruitIO_Data *data) { @@ -120,5 +119,4 @@ void handleMessage(AdafruitIO_Data *data) { Serial.println(received_lon, 6); Serial.print("ele: "); Serial.println(received_ele, 2); - } diff --git a/examples/adafruitio_05_type_conversion/adafruitio_05_type_conversion.ino b/examples/adafruitio_05_type_conversion/adafruitio_05_type_conversion.ino index 4d6068c2..e29ab6ca 100644 --- a/examples/adafruitio_05_type_conversion/adafruitio_05_type_conversion.ino +++ b/examples/adafruitio_05_type_conversion/adafruitio_05_type_conversion.ino @@ -47,7 +47,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -58,7 +59,7 @@ void setup() { type->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -66,7 +67,6 @@ void setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - } void loop() { @@ -80,39 +80,39 @@ void loop() { // in order to demonstrate sending values // as different types, we will switch between // types in a loop using the current_type variable - if(current_type == 0) { + if (current_type == 0) { Serial.print("char: "); Serial.println(char_val); type->save(char_val); - } else if(current_type == 1) { + } else if (current_type == 1) { Serial.print("string: "); Serial.println(string_val); type->save(string_val); - } else if(current_type == 2) { + } else if (current_type == 2) { Serial.print("bool: "); Serial.println(bool_val); type->save(bool_val); - } else if(current_type == 3) { + } else if (current_type == 3) { Serial.print("int: "); Serial.println(int_val); type->save(int_val); - } else if(current_type == 4) { + } else if (current_type == 4) { Serial.print("unsigned int: "); Serial.println(uint_val); type->save(uint_val); - } else if(current_type == 5) { + } else if (current_type == 5) { Serial.print("long: "); Serial.println(long_val); type->save(long_val); - } else if(current_type == 6) { + } else if (current_type == 6) { Serial.print("unsigned long: "); Serial.println(ulong_val); type->save(ulong_val); - } else if(current_type == 7) { + } else if (current_type == 7) { Serial.print("double: "); Serial.println(double_val); type->save(double_val); - } else if(current_type == 8) { + } else if (current_type == 8) { Serial.print("float: "); Serial.println(float_val); type->save(float_val); @@ -122,14 +122,13 @@ void loop() { current_type++; // reset type if we have reached the end - if(current_type > 8) + if (current_type > 8) current_type = 0; Serial.println(); lastUpdate = millis(); } - } // this function will demonstrate how to convert @@ -188,5 +187,4 @@ void handleMessage(AdafruitIO_Data *data) { Serial.println(data->isFalse()); Serial.println(); - } diff --git a/examples/adafruitio_06_digital_in/adafruitio_06_digital_in.ino b/examples/adafruitio_06_digital_in/adafruitio_06_digital_in.ino index ba81cec9..d567c3c7 100644 --- a/examples/adafruitio_06_digital_in/adafruitio_06_digital_in.ino +++ b/examples/adafruitio_06_digital_in/adafruitio_06_digital_in.ino @@ -39,14 +39,15 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect(); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -54,7 +55,6 @@ void setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - } void loop() { @@ -68,13 +68,13 @@ void loop() { // grab the current state of the button. // we have to flip the logic because we are // using a pullup resistor. - if(digitalRead(BUTTON_PIN) == LOW) + if (digitalRead(BUTTON_PIN) == LOW) current = true; else current = false; // return if the value hasn't changed - if(current == last) + if (current == last) return; // save the current state to the 'digital' feed on adafruit io @@ -84,5 +84,4 @@ void loop() { // store last button state last = current; - } diff --git a/examples/adafruitio_07_digital_out/adafruitio_07_digital_out.ino b/examples/adafruitio_07_digital_out/adafruitio_07_digital_out.ino index cf03f86a..96dd71bf 100644 --- a/examples/adafruitio_07_digital_out/adafruitio_07_digital_out.ino +++ b/examples/adafruitio_07_digital_out/adafruitio_07_digital_out.ino @@ -27,14 +27,15 @@ AdafruitIO_Feed *digital = io.feed("digital"); void setup() { - + pinMode(LED_PIN, OUTPUT); - + // start the serial connection Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); @@ -47,7 +48,7 @@ void setup() { digital->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -56,7 +57,6 @@ void setup() { Serial.println(); Serial.println(io.statusText()); digital->get(); - } void loop() { @@ -66,7 +66,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } // this function is called whenever an 'digital' feed message @@ -76,11 +75,10 @@ void handleMessage(AdafruitIO_Data *data) { Serial.print("received <- "); - if(data->toPinLevel() == HIGH) + if (data->toPinLevel() == HIGH) Serial.println("HIGH"); else Serial.println("LOW"); - digitalWrite(LED_PIN, data->toPinLevel()); } diff --git a/examples/adafruitio_08_analog_in/adafruitio_08_analog_in.ino b/examples/adafruitio_08_analog_in/adafruitio_08_analog_in.ino index 99b2bbda..124b0e23 100644 --- a/examples/adafruitio_08_analog_in/adafruitio_08_analog_in.ino +++ b/examples/adafruitio_08_analog_in/adafruitio_08_analog_in.ino @@ -36,14 +36,15 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect(); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -51,7 +52,6 @@ void setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - } void loop() { @@ -66,7 +66,7 @@ void loop() { current = analogRead(PHOTOCELL_PIN); // return if the value hasn't changed - if(current == last) + if (current == last) return; // save the current state to the analog feed diff --git a/examples/adafruitio_09_analog_out/adafruitio_09_analog_out.ino b/examples/adafruitio_09_analog_out/adafruitio_09_analog_out.ino index c9022067..c9598815 100644 --- a/examples/adafruitio_09_analog_out/adafruitio_09_analog_out.ino +++ b/examples/adafruitio_09_analog_out/adafruitio_09_analog_out.ino @@ -28,25 +28,26 @@ AdafruitIO_Feed *analog = io.feed("analog"); void setup() { - // set up led pin as an analog output - #if defined(ARDUINO_ARCH_ESP32) - #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) - // New ESP32 LEDC API - ledcAttach(LED_PIN, 12000, 8); // 12 kHz PWM, 8-bit resolution - #else - // Legacy ESP32 LEDC API - ledcAttachPin(LED_PIN, 1); - ledcSetup(1, 1200, 8); - #endif - #else - pinMode(LED_PIN, OUTPUT); - #endif +// set up led pin as an analog output +#if defined(ARDUINO_ARCH_ESP32) +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) + // New ESP32 LEDC API + ledcAttach(LED_PIN, 12000, 8); // 12 kHz PWM, 8-bit resolution +#else + // Legacy ESP32 LEDC API + ledcAttachPin(LED_PIN, 1); + ledcSetup(1, 1200, 8); +#endif +#else + pinMode(LED_PIN, OUTPUT); +#endif // start the serial connection Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); @@ -59,7 +60,7 @@ void setup() { analog->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -68,7 +69,6 @@ void setup() { Serial.println(); Serial.println(io.statusText()); analog->get(); - } void loop() { @@ -78,7 +78,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } // this function is called whenever an 'analog' message diff --git a/examples/adafruitio_10_dashboard_creation/adafruitio_10_dashboard_creation.ino b/examples/adafruitio_10_dashboard_creation/adafruitio_10_dashboard_creation.ino index 574affc3..d28a984c 100644 --- a/examples/adafruitio_10_dashboard_creation/adafruitio_10_dashboard_creation.ino +++ b/examples/adafruitio_10_dashboard_creation/adafruitio_10_dashboard_creation.ino @@ -31,14 +31,15 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect(); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -48,10 +49,10 @@ void setup() { Serial.println(io.statusText()); // create the example feed if it doesn't exist - if(feed->exists()) { + if (feed->exists()) { Serial.println("Example feed exists."); } else { - if(feed->create()) { + if (feed->create()) { Serial.println("Example feed created."); } else { Serial.println("Example feed creation failed."); @@ -59,10 +60,10 @@ void setup() { } // create the example dashboard if it doesn't exist - if(dashboard->exists()) { + if (dashboard->exists()) { Serial.println("Example dashboard exists."); } else { - if(dashboard->create()) { + if (dashboard->create()) { Serial.println("Example dashboard created."); // add blocks to the dashboard using the function below addBlocks(); @@ -70,7 +71,6 @@ void setup() { Serial.println("Example dashboard creation failed."); } } - } void loop() { @@ -80,7 +80,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } void addBlocks() { @@ -137,7 +136,7 @@ void addBlocks() { Serial.print("Adding stream block... "); StreamBlock *stream = dashboard->addStreamBlock(feed); - stream->fontSize = "small"; // small, medium, or large + stream->fontSize = "small"; // small, medium, or large stream->fontColor = "green"; // green or white stream->showErrors = true; stream->showTimestamp = true; @@ -161,5 +160,4 @@ void addBlocks() { ImageBlock *image = dashboard->addImageBlock(feed); added = image->save(); Serial.println(added ? "added" : "failed"); - } diff --git a/examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino b/examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino index b26e7bde..18dfd867 100644 --- a/examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino +++ b/examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino @@ -31,7 +31,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); @@ -41,7 +42,7 @@ void setup() { group->onMessage("count-2", two); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -49,7 +50,6 @@ void setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - } void loop() { diff --git a/examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino b/examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino index cb1ac7a1..0eeb2b7d 100644 --- a/examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino +++ b/examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino @@ -28,7 +28,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); @@ -38,7 +39,7 @@ void setup() { group->onMessage("count-2", two); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -47,7 +48,8 @@ void setup() { Serial.println(); Serial.println(io.statusText()); - // force IO to update our MQTT subscription with the current values of all feeds + // force IO to update our MQTT subscription with the current values of all + // feeds group->get(); } @@ -58,10 +60,8 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } - // this function is called whenever a 'counter-1' message // is received from Adafruit IO. it was attached to // the counter-1 feed in the setup() function above. diff --git a/examples/adafruitio_13_rgb/adafruitio_13_rgb.ino b/examples/adafruitio_13_rgb/adafruitio_13_rgb.ino index bea7a696..0b762f8b 100644 --- a/examples/adafruitio_13_rgb/adafruitio_13_rgb.ino +++ b/examples/adafruitio_13_rgb/adafruitio_13_rgb.ino @@ -22,9 +22,9 @@ // default PWM pins for ESP8266. // you should change these to match PWM pins on other platforms. -#define RED_PIN 4 +#define RED_PIN 4 #define GREEN_PIN 5 -#define BLUE_PIN 2 +#define BLUE_PIN 2 // set up the 'color' feed AdafruitIO_Feed *color = io.feed("color"); @@ -35,29 +35,29 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); - - - #if defined(ARDUINO_ARCH_ESP32) // ESP32 pinMode - #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) - // New ESP32 LEDC API - ledcAttach(RED_PIN, 12000, 8); // 12 kHz PWM, 8-bit resolution - ledcAttach(GREEN_PIN, 12000, 8); - ledcAttach(BLUE_PIN, 12000, 8); - #else - // Legacy ESP32 LEDC API - ledcAttachPin(RED_PIN, 1); - ledcAttachPin(GREEN_PIN, 2); - ledcAttachPin(BLUE_PIN, 3); - ledcSetup(1, 12000, 8); - ledcSetup(2, 12000, 8); - ledcSetup(3, 12000, 8); - #endif - #else - pinMode(RED_PIN, OUTPUT); - pinMode(GREEN_PIN, OUTPUT); - pinMode(BLUE_PIN, OUTPUT); - #endif + while (!Serial) + ; + +#if defined(ARDUINO_ARCH_ESP32) // ESP32 pinMode +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) + // New ESP32 LEDC API + ledcAttach(RED_PIN, 12000, 8); // 12 kHz PWM, 8-bit resolution + ledcAttach(GREEN_PIN, 12000, 8); + ledcAttach(BLUE_PIN, 12000, 8); +#else + // Legacy ESP32 LEDC API + ledcAttachPin(RED_PIN, 1); + ledcAttachPin(GREEN_PIN, 2); + ledcAttachPin(BLUE_PIN, 3); + ledcSetup(1, 12000, 8); + ledcSetup(2, 12000, 8); + ledcSetup(3, 12000, 8); +#endif +#else + pinMode(RED_PIN, OUTPUT); + pinMode(GREEN_PIN, OUTPUT); + pinMode(BLUE_PIN, OUTPUT); +#endif // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); @@ -70,7 +70,7 @@ void setup() { color->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -80,11 +80,10 @@ void setup() { Serial.println(io.statusText()); color->get(); - // set analogWrite range for ESP8266 - #ifdef ESP8266 - analogWriteRange(255); - #endif - +// set analogWrite range for ESP8266 +#ifdef ESP8266 + analogWriteRange(255); +#endif } void loop() { @@ -94,7 +93,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } // this function is called whenever a 'color' message diff --git a/examples/adafruitio_14_neopixel/adafruitio_14_neopixel.ino b/examples/adafruitio_14_neopixel/adafruitio_14_neopixel.ino index 89a4c1ba..7cf43d71 100644 --- a/examples/adafruitio_14_neopixel/adafruitio_14_neopixel.ino +++ b/examples/adafruitio_14_neopixel/adafruitio_14_neopixel.ino @@ -21,11 +21,12 @@ #include "Adafruit_NeoPixel.h" -#define PIXEL_PIN 5 -#define PIXEL_COUNT 24 -#define PIXEL_TYPE NEO_GRB + NEO_KHZ800 +#define PIXEL_PIN 5 +#define PIXEL_COUNT 24 +#define PIXEL_TYPE NEO_GRB + NEO_KHZ800 -Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); +Adafruit_NeoPixel pixels = + Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); // set up the 'color' feed AdafruitIO_Feed *color = io.feed("color"); @@ -36,7 +37,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); @@ -49,7 +51,7 @@ void setup() { color->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -62,7 +64,6 @@ void setup() { // neopixel init pixels.begin(); pixels.show(); - } void loop() { @@ -72,7 +73,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } // this function is called whenever a 'color' message @@ -86,10 +86,9 @@ void handleMessage(AdafruitIO_Data *data) { long color = data->toNeoPixel(); - for(int i=0; i search -> "ESP32Servo" - #include +// ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo) +// installation: library manager -> search -> "ESP32Servo" +#include #else - #include +#include #endif // pin used to control the servo @@ -43,7 +43,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // tell the servo class which pin we are using servo.attach(SERVO_PIN); @@ -59,7 +60,7 @@ void setup() { servo_feed->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -68,7 +69,6 @@ void setup() { Serial.println(); Serial.println(io.statusText()); servo_feed->get(); - } void loop() { @@ -78,7 +78,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } // this function is called whenever a 'servo' message @@ -92,11 +91,10 @@ void handleMessage(AdafruitIO_Data *data) { // make sure we don't exceed the limit // of the servo. the range is from 0 // to 180. - if(angle < 0) + if (angle < 0) angle = 0; - else if(angle > 180) + else if (angle > 180) angle = 180; servo.write(angle); - } diff --git a/examples/adafruitio_17_time_subscribe/adafruitio_17_time_subscribe.ino b/examples/adafruitio_17_time_subscribe/adafruitio_17_time_subscribe.ino index 540fd7e8..d9b23cd7 100644 --- a/examples/adafruitio_17_time_subscribe/adafruitio_17_time_subscribe.ino +++ b/examples/adafruitio_17_time_subscribe/adafruitio_17_time_subscribe.ino @@ -34,7 +34,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -53,7 +54,7 @@ void setup() { // wait for an MQTT connection // NOTE: when blending the HTTP and MQTT API, always use the mqttStatus // method to check on MQTT connection status specifically - while(io.mqttStatus() < AIO_CONNECTED) { + while (io.mqttStatus() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -61,7 +62,6 @@ void setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - } void loop() { @@ -74,24 +74,20 @@ void loop() { // Because this sketch isn't publishing, we don't need // a delay() in the main program loop. - } - // message handler for the seconds feed void handleSecs(char *data, uint16_t len) { Serial.print("Seconds Feed: "); Serial.println(data); } - // message handler for the milliseconds feed void handleMillis(char *data, uint16_t len) { Serial.print("Millis Feed: "); Serial.println(data); } - // message handler for the ISO-8601 feed void handleISO(char *data, uint16_t len) { Serial.print("ISO Feed: "); diff --git a/examples/adafruitio_18_device_info/adafruitio_18_device_info.ino b/examples/adafruitio_18_device_info/adafruitio_18_device_info.ino index 0d286aac..9feeee05 100644 --- a/examples/adafruitio_18_device_info/adafruitio_18_device_info.ino +++ b/examples/adafruitio_18_device_info/adafruitio_18_device_info.ino @@ -28,7 +28,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO..."); @@ -36,7 +37,7 @@ void setup() { io.connect(); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -50,7 +51,7 @@ void setup() { WiFi.macAddress(mac); Serial.print("MAC Address: "); - for(int i=0;i<6;i++) { + for (int i = 0; i < 6; i++) { Serial.print(mac[i], HEX); } Serial.println(); @@ -71,12 +72,8 @@ void setup() { Serial.println(IO_USERNAME); Serial.print("IO Key: "); Serial.println(IO_KEY); - Serial.print("IO Status: "); + Serial.print("IO Status: "); Serial.println(io.statusText()); - -} - -void loop(){ - } +void loop() {} diff --git a/examples/adafruitio_19_deepsleep/adafruitio_19_deepsleep.ino b/examples/adafruitio_19_deepsleep/adafruitio_19_deepsleep.ino index 11cbe0d9..85d94706 100644 --- a/examples/adafruitio_19_deepsleep/adafruitio_19_deepsleep.ino +++ b/examples/adafruitio_19_deepsleep/adafruitio_19_deepsleep.ino @@ -25,10 +25,11 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while (!Serial); + while (!Serial) + ; Serial.println("Adafruit IO + DeepSleep"); - - // connect to the Adafruit IO Library + + // connect to the Adafruit IO Library connectAIO(); // set up and write to deepsleep feed @@ -36,22 +37,20 @@ void setup() { // let's go back to sleep for DEEPSLEEP_DURATION seconds... Serial.println("sleeping..."); - // Put the Huzzah into deepsleep for DEEPSLEEP_DURATION - // NOTE: Make sure Pin 16 is connected to RST - #if defined(ESP8266) - ESP.deepSleep(1000000 * 2); - #else - Serial.println("This example is not compatible with your hardware."); - #endif +// Put the Huzzah into deepsleep for DEEPSLEEP_DURATION +// NOTE: Make sure Pin 16 is connected to RST +#if defined(ESP8266) + ESP.deepSleep(1000000 * 2); +#else + Serial.println("This example is not compatible with your hardware."); +#endif } // NOOP -void loop() { -} - +void loop() {} -void feedWrite(){ - // set up `deepsleep` feed +void feedWrite() { + // set up `deepsleep` feed AdafruitIO_Feed *deepsleep = io.feed("deepsleep"); Serial.println("sending value to feed 'deepsleep"); // send data to deepsleep feed diff --git a/examples/adafruitio_20_shared_feed_write/adafruitio_20_shared_feed_write.ino b/examples/adafruitio_20_shared_feed_write/adafruitio_20_shared_feed_write.ino index 046bcbc2..de88fddd 100644 --- a/examples/adafruitio_20_shared_feed_write/adafruitio_20_shared_feed_write.ino +++ b/examples/adafruitio_20_shared_feed_write/adafruitio_20_shared_feed_write.ino @@ -1,7 +1,8 @@ // Adafruit IO Shared Feeds Write Example // desc: Example of writing a button value to a shared feed. // -// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed +// Tutorial Link: +// https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed // // Adafruit invests time and resources providing this open source code. // Please support Adafruit and open source hardware by purchasing @@ -28,7 +29,7 @@ // the Adafruit IO username of whomever owns the feed #define FEED_OWNER "AIO_FEED_OWNER" -// set up a shared feed between you and the FEED_OWNER +// set up a shared feed between you and the FEED_OWNER // make sure you have both read AND write access to this feed AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER); @@ -45,14 +46,15 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect(); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -60,7 +62,6 @@ void setup() { // we are connected Serial.println(); Serial.println(io.statusText()); - } void loop() { @@ -74,13 +75,13 @@ void loop() { // grab the current state of the button. // we have to flip the logic because we are // using a pullup resistor. - if(digitalRead(BUTTON_PIN) == LOW) + if (digitalRead(BUTTON_PIN) == LOW) current = true; else current = false; // return if the value hasn't changed - if(current == last) + if (current == last) return; // save the current state to the 'sharedFeed' feed on adafruit io @@ -90,5 +91,4 @@ void loop() { // store last button state last = current; - } diff --git a/examples/adafruitio_21_feed_read/adafruitio_21_feed_read.ino b/examples/adafruitio_21_feed_read/adafruitio_21_feed_read.ino index 7004d721..c09ee62f 100644 --- a/examples/adafruitio_21_feed_read/adafruitio_21_feed_read.ino +++ b/examples/adafruitio_21_feed_read/adafruitio_21_feed_read.ino @@ -1,5 +1,6 @@ // Adafruit IO Feed Reading -// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed +// Tutorial Link: +// https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed // // Adafruit invests time and resources providing this open source code. // Please support Adafruit and open source hardware by purchasing @@ -27,12 +28,13 @@ AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER); void setup() { - + // start the serial connection Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); @@ -45,7 +47,7 @@ void setup() { sharedFeed->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -54,7 +56,6 @@ void setup() { Serial.println(); Serial.println(io.statusText()); sharedFeed->get(); - } void loop() { @@ -64,7 +65,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } // this function is called whenever an 'sharedFeed' feed message @@ -74,5 +74,4 @@ void handleMessage(AdafruitIO_Data *data) { Serial.print("received <- "); Serial.println(data->toInt()); - } diff --git a/examples/adafruitio_22_environmental_monitor/adafruitio_22_environmental_monitor.ino b/examples/adafruitio_22_environmental_monitor/adafruitio_22_environmental_monitor.ino index a53e4c7c..8f470760 100644 --- a/examples/adafruitio_22_environmental_monitor/adafruitio_22_environmental_monitor.ino +++ b/examples/adafruitio_22_environmental_monitor/adafruitio_22_environmental_monitor.ino @@ -1,4 +1,4 @@ -// Adafruit IO Environmental Data Logger +// Adafruit IO Environmental Data Logger // Tutorial Link: https://learn.adafruit.com/adafruit-io-air-quality-monitor // // Adafruit invests time and resources providing this open source code. @@ -11,19 +11,21 @@ // // All text above must be included in any redistribution. -/************************** Adafruit IO Configuration ***********************************/ +/************************** Adafruit IO Configuration + * ***********************************/ // edit the config.h tab and enter your Adafruit IO credentials // and any additional configuration needed for WiFi, cellular, // or ethernet clients. #include "config.h" -/**************************** Sensor Configuration ***************************************/ -#include -#include -#include -#include "Adafruit_VEML6070.h" +/**************************** Sensor Configuration + * ***************************************/ #include "Adafruit_SGP30.h" +#include "Adafruit_VEML6070.h" +#include +#include +#include // BME280 Sensor Definitions #define BME_SCK 13 @@ -74,7 +76,8 @@ void setup() { Serial.begin(9600); // wait for serial monitor to open - while (!Serial); + while (!Serial) + ; Serial.println("Adafruit IO Environmental Logger"); @@ -90,8 +93,7 @@ void setup() { io.connect(); // wait for a connection - while (io.status() < AIO_CONNECTED) - { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -115,37 +117,48 @@ void loop() { // convert from celsius to degrees fahrenheit temperatureReading = temperatureReading * 1.8 + 32; - - Serial.print("Temperature = "); Serial.print(temperatureReading); Serial.println(" *F"); + + Serial.print("Temperature = "); + Serial.print(temperatureReading); + Serial.println(" *F"); // Read the pressure from the BME280 pressureReading = bme.readPressure() / 100.0F; - Serial.print("Pressure = "); Serial.print(pressureReading); Serial.println(" hPa"); + Serial.print("Pressure = "); + Serial.print(pressureReading); + Serial.println(" hPa"); // Read the altitude from the BME280 altitudeReading = bme.readAltitude(SEALEVELPRESSURE_HPA); - Serial.print("Approx. Altitude = "); Serial.print(altitudeReading); Serial.println(" m"); - + Serial.print("Approx. Altitude = "); + Serial.print(altitudeReading); + Serial.println(" m"); + // Read the humidity from the BME280 humidityReading = bme.readHumidity(); - Serial.print("Humidity = "); Serial.print(humidityReading); Serial.println("%"); + Serial.print("Humidity = "); + Serial.print(humidityReading); + Serial.println("%"); // VEML6070 uvReading = uv.readUV(); - Serial.print("UV Light Level: "); Serial.println(uvReading); - - if(! sgp.IAQmeasure()){ - tvocReading = -1; - ecO2Reading = -1; - } - else - { - tvocReading = sgp.TVOC; - ecO2Reading = sgp.eCO2; + Serial.print("UV Light Level: "); + Serial.println(uvReading); + + if (!sgp.IAQmeasure()) { + tvocReading = -1; + ecO2Reading = -1; + } else { + tvocReading = sgp.TVOC; + ecO2Reading = sgp.eCO2; } - - Serial.print("TVOC: "); Serial.print(tvocReading); Serial.print(" ppb\t"); - Serial.print("eCO2: "); Serial.print(ecO2Reading); Serial.println(" ppm"); + + Serial.print("TVOC: "); + Serial.print(tvocReading); + Serial.print(" ppb\t"); + Serial.print("eCO2: "); + Serial.print(ecO2Reading); + Serial.println(" ppm"); // send data to Adafruit IO feeds temperatureFeed->save(temperatureReading); @@ -162,10 +175,10 @@ void loop() { // Set up the SGP30 sensor void setupSGP30() { - if (!sgp.begin()) - { + if (!sgp.begin()) { Serial.println("Sensor not found :("); - while (1); + while (1) + ; } Serial.print("Found SGP30 serial #"); Serial.print(sgp.serialnumber[0], HEX); @@ -173,18 +186,18 @@ void setupSGP30() { Serial.println(sgp.serialnumber[2], HEX); // If you previously calibrated the sensor in this environment, - // you can assign it to self-calibrate (replace the values with your baselines): - // sgp.setIAQBaseline(0x8E68, 0x8F41); + // you can assign it to self-calibrate (replace the values with your + // baselines): sgp.setIAQBaseline(0x8E68, 0x8F41); } // Set up the BME280 sensor void setupBME280() { bool status; status = bme.begin(); - if (!status) - { + if (!status) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); - while (1); + while (1) + ; } Serial.println("BME Sensor is set up!"); } \ No newline at end of file diff --git a/examples/adafruitio_23_ifttt/adafruitio_23_ifttt.ino b/examples/adafruitio_23_ifttt/adafruitio_23_ifttt.ino index 1d9426fc..56a18e0c 100644 --- a/examples/adafruitio_23_ifttt/adafruitio_23_ifttt.ino +++ b/examples/adafruitio_23_ifttt/adafruitio_23_ifttt.ino @@ -20,11 +20,11 @@ // Import Servo Libraries #if defined(ARDUINO_ARCH_ESP32) - // ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo) - // installation: library manager -> search -> "ESP32Servo" - #include +// ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo) +// installation: library manager -> search -> "ESP32Servo" +#include #else - #include +#include #endif /************************ Example Starts Here *******************************/ @@ -53,7 +53,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("IFTTT Gmailbox"); @@ -71,7 +72,7 @@ void setup() { gmail_feed->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -83,7 +84,6 @@ void setup() { // write flag to down position servo.write(FLAG_DOWN); - } void loop() { @@ -93,7 +93,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } // this function is called whenever a 'gmail' message diff --git a/examples/adafruitio_24_zapier/adafruitio_24_zapier.ino b/examples/adafruitio_24_zapier/adafruitio_24_zapier.ino index b0f74f4c..c31afbf8 100644 --- a/examples/adafruitio_24_zapier/adafruitio_24_zapier.ino +++ b/examples/adafruitio_24_zapier/adafruitio_24_zapier.ino @@ -19,10 +19,10 @@ #include "config.h" /************************ Example Starts Here *******************************/ -#include #include -#include #include +#include +#include // Prop-Maker Wing #define NEOPIXEL_PIN 2 @@ -38,7 +38,8 @@ Adafruit_LIS3DH lis = Adafruit_LIS3DH(); // NeoPixel Setup -Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800); +Adafruit_NeoPixel strip = + Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800); // Set up the 'cubeTask' feed AdafruitIO_Feed *cubetask = io.feed("cubetask"); @@ -47,7 +48,7 @@ AdafruitIO_Feed *cubetask = io.feed("cubetask"); * 1: Cube Tilted Left * 2: Cube Tilted Right * 3: Cube Neutral, Top -*/ + */ int cubeState = 0; // Previous cube orientation state @@ -66,8 +67,7 @@ unsigned long prevTime; int seconds = 0; int minutes = 0; -void setup() -{ +void setup() { // start the serial connection Serial.begin(9600); // wait for serial monitor to open @@ -80,8 +80,7 @@ void setup() digitalWrite(POWER_PIN, HIGH); // Initialize LIS3DH - if (!lis.begin(0x18)) - { + if (!lis.begin(0x18)) { Serial.println("Couldnt start"); while (1) ; @@ -98,8 +97,7 @@ void setup() io.connect(); // wait for a connection - while (io.status() < AIO_CONNECTED) - { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -109,30 +107,25 @@ void setup() Serial.println(io.statusText()); } -void updateTime() -{ +void updateTime() { // grab the current time from millis() currentTime = millis() / 1000; seconds = currentTime - prevTime; // increase mins. - if (seconds == 60) - { + if (seconds == 60) { prevTime = currentTime; minutes++; } } -void updatePixels(uint8_t red, uint8_t green, uint8_t blue) -{ - for (int p = 0; p < NUM_PIXELS; p++) - { +void updatePixels(uint8_t red, uint8_t green, uint8_t blue) { + for (int p = 0; p < NUM_PIXELS; p++) { strip.setPixelColor(p, red, green, blue); } strip.show(); } -void loop() -{ +void loop() { // io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to @@ -147,23 +140,16 @@ void loop() lis.getEvent(&event); // Detect cube face orientation - if (event.acceleration.x > 9 && event.acceleration.x < 10) - { - //Serial.println("Cube TILTED: Left"); + if (event.acceleration.x > 9 && event.acceleration.x < 10) { + // Serial.println("Cube TILTED: Left"); cubeState = 1; - } - else if (event.acceleration.x < -9) - { - //Serial.println("Cube TILTED: Right"); + } else if (event.acceleration.x < -9) { + // Serial.println("Cube TILTED: Right"); cubeState = 2; - } - else if (event.acceleration.y < 0 && event.acceleration.y > -1) - { + } else if (event.acceleration.y < 0 && event.acceleration.y > -1) { cubeState = 3; - } - else - { // orientation not specified - //Serial.println("Cube Idle..."); + } else { // orientation not specified + // Serial.println("Cube Idle..."); } // return if the orientation hasn't changed @@ -171,19 +157,18 @@ void loop() return; // Send to Adafruit IO based off of the orientation of the cube - switch (cubeState) - { + switch (cubeState) { case 1: Serial.println("Switching to Task 1"); // update the neopixel strip updatePixels(50, 0, 0); - // play a sound - #if defined(ARDUINO_ARCH_ESP32) - ledcWriteTone(PIEZO_PIN, 650); - #else - tone(PIEZO_PIN, 650, 300); - #endif +// play a sound +#if defined(ARDUINO_ARCH_ESP32) + ledcWriteTone(PIEZO_PIN, 650); +#else + tone(PIEZO_PIN, 650, 300); +#endif Serial.print("Sending to Adafruit IO -> "); Serial.println(taskTwo); @@ -196,12 +181,12 @@ void loop() // update the neopixel strip updatePixels(0, 50, 0); - // play a sound - #if defined(ARDUINO_ARCH_ESP32) - ledcWriteTone(PIEZO_PIN, 850); - #else - tone(PIEZO_PIN, 850, 300); - #endif +// play a sound +#if defined(ARDUINO_ARCH_ESP32) + ledcWriteTone(PIEZO_PIN, 850); +#else + tone(PIEZO_PIN, 850, 300); +#endif Serial.print("Sending to Adafruit IO -> "); Serial.println(taskOne); @@ -212,12 +197,12 @@ void loop() case 3: updatePixels(0, 0, 50); - // play a sound - #if defined(ARDUINO_ARCH_ESP32) - ledcWriteTone(PIEZO_PIN, 950); - #else - tone(PIEZO_PIN, 950, 300); - #endif +// play a sound +#if defined(ARDUINO_ARCH_ESP32) + ledcWriteTone(PIEZO_PIN, 950); +#else + tone(PIEZO_PIN, 950, 300); +#endif break; } diff --git a/examples/adafruitio_25_schedule_trigger/adafruitio_25_schedule_trigger.ino b/examples/adafruitio_25_schedule_trigger/adafruitio_25_schedule_trigger.ino index 3490d53a..45f0892f 100644 --- a/examples/adafruitio_25_schedule_trigger/adafruitio_25_schedule_trigger.ino +++ b/examples/adafruitio_25_schedule_trigger/adafruitio_25_schedule_trigger.ino @@ -1,5 +1,6 @@ // Adafruit IO Schedule Trigger Example -// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-scheduled-triggers/ +// Tutorial Link: +// https://learn.adafruit.com/adafruit-io-basics-scheduled-triggers/ // // Adafruit invests time and resources providing this open source code. // Please support Adafruit and open source hardware by purchasing @@ -20,7 +21,6 @@ /************************ Example Starts Here *******************************/ - // Relay is connected to PyPortal's D3 connector #define RELAY_POWER_PIN 3 @@ -33,7 +33,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -47,7 +48,7 @@ void setup() { relay->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -58,7 +59,6 @@ void setup() { // Get the last known value from the feed relay->get(); - } void loop() { @@ -68,7 +68,6 @@ void loop() { // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); - } // this function is called whenever an 'relay' feed message @@ -81,15 +80,14 @@ void handleMessage(AdafruitIO_Data *data) { // Check to see if the morning scheduled trigger has executed if (strcmp(data->toChar(), "1") == 0) { - Serial.println("Turning lights ON"); - digitalWrite(RELAY_POWER_PIN, HIGH); + Serial.println("Turning lights ON"); + digitalWrite(RELAY_POWER_PIN, HIGH); } // Check to see if the evening scheduled trigger has executed else if (strcmp(data->toChar(), "0") == 0) { - Serial.println("Turning lights OFF"); - digitalWrite(RELAY_POWER_PIN, LOW); - } - else { - Serial.println("Unexpected data received from Adafruit IO"); + Serial.println("Turning lights OFF"); + digitalWrite(RELAY_POWER_PIN, LOW); + } else { + Serial.println("Unexpected data received from Adafruit IO"); } } diff --git a/examples/adafruitio_26_led_btn/adafruitio_26_led_btn.ino b/examples/adafruitio_26_led_btn/adafruitio_26_led_btn.ino index e4958ec7..a0bacec4 100644 --- a/examples/adafruitio_26_led_btn/adafruitio_26_led_btn.ino +++ b/examples/adafruitio_26_led_btn/adafruitio_26_led_btn.ino @@ -48,7 +48,8 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.print("Connecting to Adafruit IO"); @@ -62,7 +63,7 @@ void setup() { led->onMessage(handleMessage); // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -71,7 +72,6 @@ void setup() { Serial.println(); Serial.println(io.statusText()); led->get(); - } void loop() { @@ -83,22 +83,22 @@ void loop() { io.run(); // grab the btn_state state of the button. - if(digitalRead(BUTTON_PIN) == LOW) + if (digitalRead(BUTTON_PIN) == LOW) btn_state = false; else btn_state = true; // return if the btn state hasn't changed - if(btn_state == prv_btn_state) + if (btn_state == prv_btn_state) return; // save the btn_state state to the 'button' feed on adafruit io - Serial.print("sending button -> "); Serial.println(btn_state); + Serial.print("sending button -> "); + Serial.println(btn_state); button->save(btn_state); // store last button state prv_btn_state = btn_state; - } // this function is called whenever a 'led' message @@ -107,7 +107,7 @@ void loop() { void handleMessage(AdafruitIO_Data *data) { Serial.print("received <- "); - if(data->toPinLevel() == HIGH) + if (data->toPinLevel() == HIGH) Serial.println("HIGH"); else Serial.println("LOW"); diff --git a/examples/adafruitio_27_wifimanager/adafruitio_27_wifimanager.ino b/examples/adafruitio_27_wifimanager/adafruitio_27_wifimanager.ino index 647d053e..046dd6cc 100644 --- a/examples/adafruitio_27_wifimanager/adafruitio_27_wifimanager.ino +++ b/examples/adafruitio_27_wifimanager/adafruitio_27_wifimanager.ino @@ -14,8 +14,8 @@ * */ -#include #include "AdafruitIO_WiFi.h" +#include char IO_USERNAME[64] = "my username"; char IO_KEY[64] = "my key"; @@ -24,8 +24,7 @@ AdafruitIO_Feed *myfeed = io.feed("myfeed"); WiFiManager wifiManager; -void handleMessage(AdafruitIO_Data *data) -{ +void handleMessage(AdafruitIO_Data *data) { Serial.print("received <- "); Serial.println(data->toString()); @@ -40,20 +39,22 @@ void setup() // wifiManager.resetSettings(); //uncomment to reset the WiFi settings - wifiManager.setClass("invert"); // enable "dark mode" for the config portal - wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds - wifiManager.setAPClientCheck(true); // avoid timeout if client connected to softap + wifiManager.setClass("invert"); // enable "dark mode" for the config portal + wifiManager.setConfigPortalTimeout( + 120); // auto close configportal after n seconds + wifiManager.setAPClientCheck( + true); // avoid timeout if client connected to softap - if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing setting or start config + if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing + // setting or start config { Serial.println("failed to connect and hit timeout"); - } - else - { + } else { // if you get here you have connected to the WiFi Serial.println("Connected to WiFi."); - Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", IO_USERNAME, IO_KEY); + Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", + IO_USERNAME, IO_KEY); io.connect(); myfeed->onMessage(handleMessage); @@ -62,8 +63,7 @@ void setup() // wait for a connection - while ((io.status() < AIO_CONNECTED)) - { + while ((io.status() < AIO_CONNECTED)) { Serial.print("."); delay(500); } @@ -72,9 +72,4 @@ void setup() } // setup() -void loop() -{ - - io.run(); - -} // loop() +void loop() { io.run(); } // loop() diff --git a/examples/adafruitio_28_wifimanager-custom-aio-parameters/adafruitio_28_wifimanager-custom-aio-parameters.ino b/examples/adafruitio_28_wifimanager-custom-aio-parameters/adafruitio_28_wifimanager-custom-aio-parameters.ino index 678786cb..17709503 100644 --- a/examples/adafruitio_28_wifimanager-custom-aio-parameters/adafruitio_28_wifimanager-custom-aio-parameters.ino +++ b/examples/adafruitio_28_wifimanager-custom-aio-parameters/adafruitio_28_wifimanager-custom-aio-parameters.ino @@ -5,22 +5,23 @@ * to the network instead of defining the WiFI SSID and password * explicitly in the code. * - * In addition, this example allows you to enter your Adafruit IO username and key - * as customer parameters in WiFiManager so that they do not need to be coded into - * the sketch. - * + * In addition, this example allows you to enter your Adafruit IO username and + * key as customer parameters in WiFiManager so that they do not need to be + * coded into the sketch. + * * This is useful if you want to create projects and share them with others that - * may use them on a different WiFi network and use a different Adafruit IO account - * for IOT integrations such as collecting sensor data or voice command integration via - * IFFT. + * may use them on a different WiFi network and use a different Adafruit IO + * account for IOT integrations such as collecting sensor data or voice command + * integration via IFFT. * * To use this example, setup a feed called "myfeed". When the ESP8266 or ESP32 - * microcontroller starts, join the "WiFi Setup" SSID and you should be presented - * with the config portal. If the config portal does not automatically start you - * can browse to http://192.168.4.1 to access it + * microcontroller starts, join the "WiFi Setup" SSID and you should be + * presented with the config portal. If the config portal does not + * automatically start you can browse to http://192.168.4.1 to access it * * Select the SSID and enter the password for WiFi Access in the config portal. - * Enter your Adafruit IO username and key in the config portal and select "Save". + * Enter your Adafruit IO username and key in the config portal and select + * "Save". * * When you manually add data to the feed on io.adafruit.com, you'll see * that data written to the serial output. @@ -29,25 +30,25 @@ * */ -#include #include "AdafruitIO_WiFi.h" #include #include +#include char IO_USERNAME[64] = ""; char IO_KEY[64] = ""; static uint8_t objStorage[sizeof(AdafruitIO_WiFi)]; // RAM for the object -AdafruitIO_WiFi *io; // a pointer to the object, once it's constructed +AdafruitIO_WiFi *io; // a pointer to the object, once it's constructed // create WiFiManager object and define our custom parameters WiFiManager wifiManager; -WiFiManagerParameter custom_IO_USERNAME("iouser", "Adafruit IO Username", IO_USERNAME, 60); +WiFiManagerParameter custom_IO_USERNAME("iouser", "Adafruit IO Username", + IO_USERNAME, 60); WiFiManagerParameter custom_IO_KEY("iokey", "Adafruit IO Key", IO_KEY, 60); -void handleMessage(AdafruitIO_Data *data) -{ +void handleMessage(AdafruitIO_Data *data) { Serial.print("received <- "); Serial.println(data->toString()); @@ -55,8 +56,7 @@ void handleMessage(AdafruitIO_Data *data) } // handleMessage // callback notifying us of the need to save config -void saveConfigCallback() -{ +void saveConfigCallback() { Serial.println("Saving new config"); @@ -69,8 +69,7 @@ void saveConfigCallback() json["IO_USERNAME"] = IO_USERNAME; File configFile = LittleFS.open("/config.json", "w"); - if (!configFile) - { + if (!configFile) { Serial.println("Failed to open config file for writing"); } @@ -81,19 +80,15 @@ void saveConfigCallback() configFile.close(); } // end save -void readParamsFromFS() -{ - if (LittleFS.begin()) - { +void readParamsFromFS() { + if (LittleFS.begin()) { - if (LittleFS.exists("/config.json")) - { + if (LittleFS.exists("/config.json")) { // file exists, reading and loading Serial.println("Reading config file"); File configFile = LittleFS.open("/config.json", "r"); - if (configFile) - { + if (configFile) { size_t size = configFile.size(); // Allocate a buffer to store contents of the file. std::unique_ptr buf(new char[size]); @@ -104,24 +99,20 @@ void readParamsFromFS() auto deserializeError = deserializeJson(json, buf.get()); serializeJson(json, Serial); Serial.println(); - if (!deserializeError) - { + if (!deserializeError) { if (json.containsKey("IO_USERNAME")) strcpy(IO_USERNAME, json["IO_USERNAME"]); if (json.containsKey("IO_KEY")) strcpy(IO_KEY, json["IO_KEY"]); - } - else - { + } else { Serial.println("Failed to load json config"); } configFile.close(); } } - else - { + else { Serial.println("Failed to mount FS"); } } @@ -135,26 +126,29 @@ void setup() readParamsFromFS(); // get parameters from file system - //wifiManager.resetSettings(); //uncomment to reset the WiFi settings + // wifiManager.resetSettings(); //uncomment to reset the WiFi settings - wifiManager.setClass("invert"); // enable "dark mode" for the config portal - wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds - wifiManager.setAPClientCheck(true); // avoid timeout if client connected to softap + wifiManager.setClass("invert"); // enable "dark mode" for the config portal + wifiManager.setConfigPortalTimeout( + 120); // auto close configportal after n seconds + wifiManager.setAPClientCheck( + true); // avoid timeout if client connected to softap - wifiManager.addParameter(&custom_IO_USERNAME); // set custom paraeter for IO username - wifiManager.addParameter(&custom_IO_KEY); // set custom parameter for IO key + wifiManager.addParameter( + &custom_IO_USERNAME); // set custom paraeter for IO username + wifiManager.addParameter(&custom_IO_KEY); // set custom parameter for IO key custom_IO_KEY.setValue(IO_KEY, 64); // set custom parameter value custom_IO_USERNAME.setValue(IO_USERNAME, 64); // set custom parameter value - wifiManager.setSaveConfigCallback(saveConfigCallback); // set config save notify callback + wifiManager.setSaveConfigCallback( + saveConfigCallback); // set config save notify callback - if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing setting or start config + if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing + // setting or start config { Serial.println("Failed to connect and hit timeout"); - } - else - { + } else { // if you get here you have connected to the WiFi Serial.println("Connected to WiFi."); @@ -162,7 +156,8 @@ void setup() io = new (objStorage) AdafruitIO_WiFi(IO_USERNAME, IO_KEY, "", ""); - Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", IO_USERNAME, IO_KEY); + Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", + IO_USERNAME, IO_KEY); io->connect(); @@ -174,8 +169,7 @@ void setup() // wait for a connection - while ((io->status() < AIO_CONNECTED)) - { + while ((io->status() < AIO_CONNECTED)) { Serial.print("."); delay(500); } @@ -184,9 +178,4 @@ void setup() } // setup() -void loop() -{ - - io->run(); - -} // loop() +void loop() { io->run(); } // loop() diff --git a/examples/io_home_series/io_home_security/io_home_security.ino b/examples/io_home_series/io_home_security/io_home_security.ino index 55345106..9fcdb3b0 100644 --- a/examples/io_home_series/io_home_security/io_home_security.ino +++ b/examples/io_home_series/io_home_security/io_home_security.ino @@ -23,12 +23,12 @@ #include "Adafruit_NeoPixel.h" // include the SGP30 library -#include #include "Adafruit_SGP30.h" +#include /************************ Example Starts Here *******************************/ -// delay the main `io.run()` loop +// delay the main `io.run()` loop #define LOOP_DELAY 3000 // delay for each sensor send to adafruit io #define SENSOR_DELAY 1000 @@ -54,17 +54,17 @@ unsigned long currentTime = 0; unsigned long prevTime = 0; int currentHour = startingHour; - /*********NeoPixel Setup*********/ // pin the NeoPixel strip and jewel are connected to -#define NEOPIXEL_PIN 12 +#define NEOPIXEL_PIN 12 // amount of neopixels on the NeoPixel strip -#define STRIP_PIXEL_COUNT 60 -#define JEWEL_PIXEL_COUNT 7 +#define STRIP_PIXEL_COUNT 60 +#define JEWEL_PIXEL_COUNT 7 // type of neopixels used by the NeoPixel strip and jewel. -#define PIXEL_TYPE NEO_GRB + NEO_KHZ800 +#define PIXEL_TYPE NEO_GRB + NEO_KHZ800 // init. neoPixel Strip -Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, NEOPIXEL_PIN, PIXEL_TYPE); +Adafruit_NeoPixel strip = + Adafruit_NeoPixel(STRIP_PIXEL_COUNT, NEOPIXEL_PIN, PIXEL_TYPE); // sketch starts assuming no motion is detected int pirState = LOW; @@ -85,7 +85,7 @@ AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights"); // `front-door` feed AdafruitIO_Feed *frontDoor = io.feed("front-door"); // `motion-detector` feed -AdafruitIO_Feed *motionFeed = io.feed("motion-detector"); +AdafruitIO_Feed *motionFeed = io.feed("motion-detector"); // `home-alarm` feed AdafruitIO_Feed *homeAlarm = io.feed("home-alarm"); // 'tvoc' feed @@ -98,13 +98,14 @@ void setup() { Serial.begin(115200); // wait for serial monitor to open - while(! Serial); + while (!Serial) + ; Serial.println("Adafruit IO Home: Security"); - + Serial.println("Connecting to Adafruit IO"); // start MQTT connection to io.adafruit.com io.connect(); - + // attach a message handler for the `home-alarm` feed homeAlarm->onMessage(handleAlarm); // subscribe to lighting feeds and register message handlers @@ -114,14 +115,14 @@ void setup() { // wait for an MQTT connection // NOTE: when blending the HTTP and MQTT API, always use the mqttStatus // method to check on MQTT connection status specifically - while(io.mqttStatus() < AIO_CONNECTED) { + while (io.mqttStatus() < AIO_CONNECTED) { Serial.print("."); delay(500); } // we are connected Serial.println(); Serial.println(io.statusText()); - + // declare PIR sensor as input pinMode(pirPin, INPUT); // declare reed switch as input @@ -132,8 +133,8 @@ void setup() { strip.begin(); strip.show(); } - -void loop(){ + +void loop() { // io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to @@ -150,36 +151,36 @@ void loop(){ // check if the alarm toggle is armed from the dashboard if (isAlarm == true) { - if (doorState == HIGH || (currentHour>alarmHour && pirState == HIGH)) { + if (doorState == HIGH || (currentHour > alarmHour && pirState == HIGH)) { playAlarmAnimation(); - } + } } } void playAlarmAnimation() { -// plays the alarm piezo buzzer and turn on/off neopixels - Serial.println("ALARM TRIGGERED!"); - - #if defined(ARDUINO_ARCH_ESP32) - // ESP32 doesn't use native tone() function - ledcWriteTone(piezoPin, 220); - #else - tone(piezoPin, 220, 2); - #endif - - for(int i=0; isave(3); pirState = HIGH; } - } - else { + } else { if (pirState == HIGH) { Serial.println("* Motion ended."); motionFeed->save(0); @@ -213,26 +213,30 @@ void readPIR() { } void readSGP30() { -// reads the SGP30 sensor and sends data to Adafruit IO - if (! sgp.IAQmeasure()) { + // reads the SGP30 sensor and sends data to Adafruit IO + if (!sgp.IAQmeasure()) { Serial.println("Measurement failed"); return; } - Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t"); - Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm"); + Serial.print("TVOC "); + Serial.print(sgp.TVOC); + Serial.print(" ppb\t"); + Serial.print("eCO2 "); + Serial.print(sgp.eCO2); + Serial.println(" ppm"); tvocFeed->save(int(sgp.TVOC)); - delay(SENSOR_DELAY/2); + delay(SENSOR_DELAY / 2); eco2Feed->save(int(sgp.eCO2)); - delay(SENSOR_DELAY/2); + delay(SENSOR_DELAY / 2); } /*** MQTT messageHandlers ***/ void handleAlarm(AdafruitIO_Data *data) { -// handle the alarm toggle on the Adafruit IO Dashboard + // handle the alarm toggle on the Adafruit IO Dashboard String toggleValue = data->toString(); Serial.print("> rcv alarm: "); Serial.println(toggleValue); - if(toggleValue == String("ON")) { + if (toggleValue == String("ON")) { Serial.println("* Alarm Set: ON"); isAlarm = true; } else { @@ -247,7 +251,7 @@ void indoorLightHandler(AdafruitIO_Data *data) { Serial.println(data->value()); long color = data->toNeoPixel(); // set the color of each NeoPixel in the jewel - for(int i=0; i outdoor light HEX: "); Serial.println(data->value()); long color = data->toNeoPixel(); - // set the color of each NeoPixel in the strip - for(int i=JEWEL_PIXEL_COUNT; ionMessage(indoorLightHandler); outdoorLights->onMessage(outdoorLightHandler); - // wait for a connection - while(io.status() < AIO_CONNECTED) { + while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } @@ -90,10 +93,11 @@ void setup() { // initalize the Si7021 sensor if (!sensor.begin()) { Serial.println("Did not find Si7021 sensor!"); - while (true); + while (true) + ; } Serial.println("Si7021 sensor set up!"); - + // initalize the neopixel strip and jewel. strip.begin(); jewel.begin(); @@ -113,7 +117,6 @@ void loop() { temperatureData = sensor.readTemperature() * 1.8 + 32; humidityData = sensor.readHumidity(); - Serial.print("-> Sending Temperature to Adafruit IO: "); Serial.println(temperatureData); Serial.print("-> Sending Humidity to Adafruit IO: "); @@ -122,9 +125,9 @@ void loop() { // send the state of the feed to adafruit io temperature->save(temperatureData); humidity->save(humidityData); - + // delay the loop to avoid flooding Adafruit IO - delay(1000*TEMP_DELAY); + delay(1000 * TEMP_DELAY); } void indoorLightHandler(AdafruitIO_Data *data) { @@ -134,7 +137,7 @@ void indoorLightHandler(AdafruitIO_Data *data) { long color = data->toNeoPixel(); // set the color of each NeoPixel in the jewel - for(int i=0; itoNeoPixel(); - // set the color of each NeoPixel in the strip - for(int i=0; i Date: Tue, 17 Feb 2026 15:34:53 -0500 Subject: [PATCH 2/2] Fix macro formatting for CI clang-format version Co-authored-by: ladyada --- src/AdafruitIO_Definitions.h | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/AdafruitIO_Definitions.h b/src/AdafruitIO_Definitions.h index 34762d6f..70080c80 100644 --- a/src/AdafruitIO_Definitions.h +++ b/src/AdafruitIO_Definitions.h @@ -79,39 +79,27 @@ class AdafruitIOGroupCallback { // Define actual debug output functions when necessary. #ifdef AIO_DEBUG #define AIO_DEBUG_PRINT(...) \ - { \ - AIO_PRINTER.print(__VA_ARGS__); \ - } ///< Prints debug output. + { AIO_PRINTER.print(__VA_ARGS__); } ///< Prints debug output. #define AIO_DEBUG_PRINTLN(...) \ - { \ - AIO_PRINTER.println(__VA_ARGS__); \ - } ///< Prints line from debug output. + { AIO_PRINTER.println(__VA_ARGS__); } ///< Prints line from debug output. #else #define AIO_DEBUG_PRINT(...) \ - { \ - } ///< Prints debug output + {} ///< Prints debug output #define AIO_DEBUG_PRINTLN(...) \ - { \ - } ///< Prints line from debug output. + {} ///< Prints line from debug output. #endif // Define actual error output functions when necessary. #ifdef AIO_ERROR #define AIO_ERROR_PRINT(...) \ - { \ - AIO_PRINTER.print(__VA_ARGS__); \ - } ///< Prints error output + { AIO_PRINTER.print(__VA_ARGS__); } ///< Prints error output #define AIO_ERROR_PRINTLN(...) \ - { \ - AIO_PRINTER.println(__VA_ARGS__); \ - } ///< Prints line from error output + { AIO_PRINTER.println(__VA_ARGS__); } ///< Prints line from error output #else #define AIO_ERROR_PRINT(...) \ - { \ - } ///< Prints error output. + {} ///< Prints error output. #define AIO_ERROR_PRINTLN(...) \ - { \ - } ///< Prints line from error output. + {} ///< Prints line from error output. #endif #define AIO_PING_INTERVAL 60000 ///< Adafruit IO Ping Interval, in milliseconds