How to Organize Code
Programming Electronics Academy
@programmingelectronicsAbout
Want to build confidence programming your electronics project? You're in the right place! At Programming Electronics Academy we are all about teaching programming and electronics with Arduino and other popular tools for prototyping your awesome ideas. We understand you might be new to programming so we strive to keep our tutorials simple without watering them down. Here you'll find videos that cover Arduino programming, hardware, common questions, and detailed walk throughs. Subscribe now, and start mapping out your Arduino training today! We release new tutorial twice a month, and have a weekly live show that dives into Arduino programming every Friday at 10AM EST.
Latest Posts
Video Description
π€© Get the 10 Arduino Programming Tips PDF hereππ https://bit.ly/4p6pYkc ***Want to learn more? Check out our courses!*** https://bit.ly/3DQBw4J ***Get your Free Trial of Altium PCB design Software*** https://www.altium.com/yt/programmingelectronicsacademy Arduino Sketch Build Process Website: https://arduino.github.io/arduino-cli/dev/sketch-build-process/ ***Get the code, transcript, challenges, etc for this lesson on our website*** https://bit.ly/38kpPrC ***We designed this circuit board for beginners!*** Kit-On-A-Shield: https://amzn.to/3lfWClU FOLLOW US ELSEWHERE --------------------------------------------------- Facebook: https://www.facebook.com/ProgrammingElectronicsAcademy/ Twitter: https://twitter.com/ProgElecAcademy Website: https://www.programmingelectronics.com/ ________________________________ If you are new to writing code with Arduino it can be confusing on how to organize the program. But once you know where stuff goes in an Arduino program it's actually pretty simple. In this lesson, you are gonna learn how to organize the key components of an Arduino sketch like includes, define, constants, global variables, functions, setup and loop. Let's dive in. All right, so here I am in the Arduino IDE and it doesn't matter which IDE you're using. You could be in the online, editor or maybe you're in the Arduino 2.0 IDE. It really doesn't matter or maybe you're in VS Code. It doesn't matter where you're programming this stuff. It's all gonna be the same as far as this organization goes. Okay, so we open up a new sketch and what Arduino does is it pre-populates two functions in here. It gives a setup and loop. We're gonna visit these later but right now I'm just gonna go ahead and delete that 'cause what I wanna do is start from just a blank slate. All right, so what I'm gonna do just in comments is kind of list out all the stuff in the order that we're gonna want it generally. All right, so here's the basic order, now of course every rule has exceptions and this is definitely a rule that has exceptions, but here's the rough order we wanna lay stuff out in an Arduino sketch. First you're gonna start off with including libraries. So if you have any libraries that you're using with your sketch, putting them at the very top is generally where you're gonna see them. So an easy way to include a library is just to go up to sketch, include library and then select the library you want to include. I'll use FastLED for this example and you'll see it just inserts this line include and then the name of the library right at the top. So I'll just go ahead and move this down to where I've got the comment. Of course, we could always just write this out on our own. The nice thing about using the shortcut up in sketch with the included library is that you know you're not gonna make any spelling errors. And as simple as that might be sometimes a spelling error can throw you for a loop for a little bit. All right, so you wanna include your libraries at the very top of the sketch. So the next thing you'll want after you include the libraries is to add your constants and any defines. And also you'll wanna have your global variables. Now you can have these intermingles, so you might have a constant and then you could hav CONTINUED... https://bit.ly/38kpPrC ***About Us:*** This Arduino lesson was created by Programming Electronics Academy. We are an online education company who seeks to help people learn about electronics and programming through the ubiquitous Arduino development board. ***We have no affiliation whatsoever with Arduino LLC, other than we think they are cool.***
Upgrade Your Everyday
AI-recommended products based on this video

Kasa Smart Outdoor Smart Plug by TP-Link (KP400) - Smart WiFi Outlet with 2 Sockets, IP64 Waterproof, Works with Alexa and Google Home, 2.4GHz WiFi Required, No Hub Required, Sunset & Sunrise Offset

Wireless Earbuds, Sports Bluetooth Headphones, 80Hrs Playtime Ear Buds with LED Power Display, Noise Canceling Headset, IPX7 Waterproof Earphones for Workout/Running Z(Black)

Monster Wireless Earbuds, Bluetooth 5.4 in Ear Stereo Headphones, Built-in Mic for Crystal Clear Call, 32H Playtime, Comfortable Fit, Fast Charging, Waterproof Earphones for Sports, Black

Wireless Earbuds, Sports Bluetooth Headphones, 80Hrs Playtime Ear Buds with LED Power Display, Noise Canceling Headset, IPX7 Waterproof Earphones for Workout/Running Z(Black)

Monster N-Lite 217 Wireless Earbuds, Immersive Stereo Sound, Bluetooth 6.0 in-Ear Headphones, Built-in Smart Noise Cancelling Mic for Clear Calls, Comfortable Fit, 32H Playtime, IPX6 Waterproof, Black

Brita Stainless Steel Premium Filtering Water Bottle, BPA-Free, Reusable, Insulated, Replaces 300 Plastic Water Bottles, Filter Lasts 2 Months or 40 Gallons, Includes 1 Filter, Carbon - 20 oz.

Simple Modern Filtered Water Bottle | Insulated Stainless-Steel Carbon Filter Travel Water Bottles | Reusable for Clean Drinking Water On The Go | 24oz, Sea Glass Sage

FITVII Health & Fitness Tracker (Answer/Make Calls), Smart Watch with 24/7 Heart Rate and Blood Pressure, Sleep Tracking Monitor, 120+ Sport Mode Activity Tracker

AYATAHA AYATAHA Smart Watch for Kids, Smartwatch Fitness Tracker for Boys Girls, Children's Activity Watch 37 Sports Modes SMS Notification, HD Full Touchscreen IP67 Waterproof, Blue

Iaret Iaret Smart Watch for Women, 1.83" HD Fitness Tracker with 4 Bands, Answer/Make Calls, Heart Rate/Sleep/SpO2/Step Tracking, 100+ Sport Modes, Android/iPhone Compatible Gift (Rose Gold)

Smart Watch for Men Women 1.8" Fitness Tracker, Bluetooth Call, DIY Dial, Heart Rate Sleep Blood Oxygen Monitor, 100+ Sports Modes, IP68 Waterproof Smartwatch for Android iPhone, Alexa Built-in

Hand Warmers 2 Pack, 14000mAh Rechargeable Hand Warmers, Electric Hand Warmer Reusable, Portable Power Bank USB Hand Warmers 4 Levels 8 Heating, Gifts for Raynauds Ski Golf Camping

Hand Warmers Rechargeable, 10000mAh Electric Heated Gloves Power Bank Portable Graphene Handwarmers Pouch with 3 Levels & Double-Sided Heating for Hunting Camping Golf Xmas Gifts for Women Men Kids

2Pack Rechargeable Hand Warmer, 8000mAh Electric Hand Warmer Power Bank, Portable USB-C Hand Warmer for Pocket, Reusable Hand Warmer Up to 8 hrs Each, Warm Gift for Men Women, for Hunting, Camping

GTOCE Portable Charger,40000mAh Power Bank with 22.5W Fast Charging LED Digital Display Battery Pack with 6 Outputs 2 Inputs, Type C Powerbank Portable Charger for iPhone 16 pro Samsung AirPods,Black

Monster Sleep Ear200, Wireless in-Ear Headphones, Bluetooth 6.0 Sleep Headphones, with ANC Active Noise Cancellation Designed for Side Sleepers, 30 Hours of bass Stereo Sound.

Monster Sleep Ear100 Ear Buds, Sleep Earbuds with Stereo Sound, Design for Side Sleeper, 32H Playtime, Bluetooth 6.0, ENC Noise Cancelling, IPX6 Waterproof Mini Headphones, White

Monster Sleep Ear100 Ear Buds, Sleep Earbuds with Stereo Sound, Design for Side Sleeper, 32H Playtime, Bluetooth 6.0, ENC Noise Cancelling, IPX6 Waterproof Mini Headphones, Black

Monster Sleep Ear100 Ear Buds, Sleep Earbuds with Stereo Sound, Design for Side Sleeper, 32H Playtime, Bluetooth 6.0, ENC Noise Cancelling, IPX6 Waterproof Mini Headphones, Black

Hydroponics Growing System Indoor Garden - Herb Garden with Grow Light, 15 Pods Stainless Steel Indoor Garden Kit, Auto Timer, Gardening Gift for All Ages

Umbra Triflora Hanging Planter for Window, Indoor Herb Garden, Set of 5, White/Black

Large Hydroponics Growing System 14 Pods, Indoor Herb Garden with LED Grow Light, 5L Water Tank, Hydroponic Grow Kit with 3 Auto-Timers, Rotatable Light Panel and Child Lock for Home School Gardening

Hanging Planter Hanging Plant Holder, 6 Inch 4 Indoor Plant Pots, Wall/Window Plant Hanger Indoor Herb Garden

slopehill Multi Hair Stylers & Hair Straightener - 2 in 1 Wet to Dry Air Straightener and Hair Dryer Combo with High Speed Air + Rapid Heat-Up + Customizable Temperature(Pink)

Hi.FANCY Portable Laptop Stand with Dual Cooling Fans for 14-17inch Laptops, Grey, 23.5 x 25.9 x 0.95cm

Laptop Stand for Desk, Adjustable Laptop Riser ABS+Silicone Foldable Portable Laptop Holder, Ventilated Cooling Notebook Stand for 10-15.6β Laptops,Tablet-Black

JETech 5 in 1 Case for Samsung Galaxy S25 Ultra 5G with 2-Pack Each Tempered Glass Screen Protector and Camera Lens Protector, Non-Yellowing Shockproof Bumper Phone Cover (Clear)

TAURI for iPhone 17 Pro Max Case 6.9" with 1-Pack Screen Protector, Camera Lens Full Protection, Military-Grade Protection, Shockproof Transparent Back Bumper Phone Cover - Clear Global Recycled Standard

TAURI for iPhone 17 Pro Case 6.3" with 1-Pack Screen Protector, Camera Lens Full Protection, Military-Grade Protection, Shockproof Transparent Back Bumper Phone Cover - Clear Global Recycled Standard

JOINPAYA 1Set Rechargeable Hand Warmer Hand Heater for Winter Heating Levels Compact

Shakven Rechargeable Hand Warmer | Cute Comfortable Portable Hand Warmers,Ergonomic Adjustable Energy-Efficient Small Heater for Travel, Outdoor, Winter

OCOOPA IP45 Waterproof Hand Warmer Rechargeable, Up to 15hrs Heat,10000mAh Durable Quick Charge Electric Hand Heater, PD Compatible, 3 Levels for Outdoors, Heavy Duty, H01-PD PRO













