Code suggestion for...
 
Notifications
Clear all

Code suggestion for movePWM function

3 Posts
2 Users
0 Likes
3,180 Views
bryan.schmidty
(@bryan-schmidty)
Active Member
Joined: 4 years ago
Posts: 3
Topic starter  

Hello! I just joined the form, and I'm excited to be a part of this community.

I was watching episode 12 of the DB1 series on YouTube. I commented about this on YouTube as well, but I thought I'd share it here as well so I could be more descriptive.

I noticed you have code to restrict the input variables to be between two values. 

if (spp > 255) spp = 255;
if (spp < 0) spp = 0;

I recently learned about the Arduino function called `constrain` ( https://www.arduino.cc/reference/en/language/functions/math/constrain/ ). I believe this could help shorten your code a bit. You could write it like this:

spp = constrain(spp, 0, 255);

I hope this helps! I love this project, and all the work you are doing. Keep it up!

Also, do you plan on putting your code on GitHub or any other open source repository? I am a programmer by trade and would enjoy seeing it all. (or maybe you already have it somewhere and I just can't find it)

Edit: fixed formatting in code block and added question about code repository

This topic was modified 4 years ago 2 times by bryan.schmidty

   
Quote
Topic Tags
DroneBot Workshop
(@dronebot-workshop)
Noble Member Admin
Joined: 4 years ago
Posts: 1170
 

Hi Bryan, and welcome to the forum!

That's an excellent idea, I'll incorporate your suggestion.  I haven't used "constrain" before, love iot when I learn something new - thanks!

And yes, I am putting everything - DB1 and all of the other projects I've done in the workshop, onto GitHub. Actually, most of it is already there but the repositories are currently set "private" as I'm fooling around with my setup on this end. I expect to have it set public sometime next week.

Thanks for your post - sorry it got "moderated" but the software does that to your first few posts, it's part of the anti-spam stuff. I try and approve them as quickly as I can.

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
ReplyQuote
bryan.schmidty
(@bryan-schmidty)
Active Member
Joined: 4 years ago
Posts: 3
Topic starter  

Sounds great! I look forward to seeing all the code.

I am a programmer, so I enjoy that part of my Arduino projects the most. I hope you don't mind if I make pull requests on GitHub for suggestions like these. One of my passions is finding ways to improve code to make it faster, more efficient, and easier to read.

No worries about the moderation; I understand. I look forward to progress on DB1! Keep up the great work!


   
ReplyQuote