Notifications
Clear all

Coding help needed

41 Posts
6 Users
17 Likes
1,877 Views
 Gunn
(@gunn)
Member
Joined: 2 years ago
Posts: 10
Topic starter  

@davee no disrespect taken! I really appreciate the feedback. I have done small projects, if / then statements, but very simple. Built a false roof in a friends hummer and controlled the opening actuator with an arduino that acted like a combination lock. But that was not as intricate as what I'm doing now. I think am trying to go from kindergarten to high school and need more time learning the basics. "Honest" isn't always kind, and "kind" is rarely honest.


   
Ron reacted
ReplyQuote
 Gunn
(@gunn)
Member
Joined: 2 years ago
Posts: 10
Topic starter  

@zander thank you for your help. I'll use this as a starting point! The bottom part of the code was ment to read the switch position and if a sensor was triggered it would stop accepting input from the switch. I understand it looks very armature, ill keep refining the code after I get the first lines in the arduino as a base to build from. If the road is paved to the cliff, I'll learn to build a bridge!


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6963
 

@gunn Have you read K&R?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
 Gunn
(@gunn)
Member
Joined: 2 years ago
Posts: 10
Topic starter  

@zander


No sir, I'm not sure what that is. If you point me in the right direction, I'll find it this weekend and start reading it while I'm camping. 


   
ReplyQuote
 Gunn
(@gunn)
Member
Joined: 2 years ago
Posts: 10
Topic starter  

Having been just a touch smarter than I should be, I just downloaded the 288 page book and have time to put a few pages behind me today on lunch.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6963
 

@gunn It's the book almost every C programmer I know started with. Although we are officialy working in C++ we seldom need the ++ unless we are writing Library code, or more complex code. 90+% of the time just knowing C will do.

Amazon links don't work well here so I will paste this several ways. NOTE it is a .com link

https://amz.run/5iw0

https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628/ref=sr_1_2?crid=2PHP3P3QI9ZQN&keywords=K%26R+C&qid=1656434793&sprefix=k%26r+c%2Caps%2C295&sr=8-2   "

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6963
 

You also need to be very familiar with the arduino.cc web site especially the Reference section. I would be at least familiar with everything there and some needs to be memorized. Don't be discouraged, it takes a couple years to become a beginner. Notice the sign in, get registered.

Screen Shot 2022 06 28 at 09.52.36
Screen Shot 2022 06 28 at 09.55.09

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@gunn 

I would just find tutorials on programming Arduino C++.

It also helps if you describe in detail, in a human language, with maybe the actual circuit and components what you are trying to do.  It is called top down programming,  much easier than trying to work it out from the code alone.

Just reading a programming book wouldn't work for me,  I learn by actually typing up actual program examples making sure I understand each line.

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@zander

Posted by: @zander

@gunn It's the book almost every C programmer I know started with. Although we are officialy working in C++ we seldom need the ++ unless we are writing Library code, or more complex code. 90+% of the time just knowing C will do.

Sorry Ron, but I digress to such advice.  There seems to be a very common misconception that learning C++ is too hard to learn (and harder than C), when in fact, this couldn't be further from the truth.

There are many examples I could provide as to why this is the case (especially for ESP8266 and ESP32, etc...), but here is just one case to prove the point, just for the UNO:

For example, is it easier to work with character arrays such as (in C)?

const char buffer* = "data"; // char (a const string literal), offers no functions to manipulate it, likewise, a C character array offers nothing more:

char buffer [some_length] = "foo_bar_baz";

buffer.NO_MEMBER_FUNCTIONS_AVAILABLE_HERE_TO_DO_ANYTHING;

vs:

String buffer = "data" // However, the Arduino String is a C++ class, and supports many MEMBER manipulation functions, such as the following:

Available (Arduino) String Functions:
String.charAt()
String.compareTo()
String.concat()
String.c_str()
String.endsWith()
String.equals()
String.equalsIgnoreCase()
String.getBytes()
String.indexOf()
String.lastIndexOf()
String.length()
String.remove()
String.replace()
String.reserve()
String.setCharAt()
String.startsWith()
String.substring()
String.toCharArray()
String.toDouble()
String.toInt()
String.toFloat()
String.toLowerCase()
String.toUpperCase()
String.trim()

Why would you want to avoid this functionality and make your life more difficult?

My advice.... always choose C++ available features, unless you encounter some constraints such as program size to available memory for your situation.  Having said that however, I think the Arduino is dead, and the C++ support and increased memory makes the ESP8266 and ESP32 and Teensy etc...are the boards of the future.

Arduino, in my view; is only good for absolute beginners these days (to learn the basic/fundamentals)... the latest micro-controllers beat the crap out of it in many, many ways, and as users become more proficient, they'll want to push their knowledge further, which is a part of the learning curve.

Cheers


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@frogandtoad

There seems to be a very common misconception that learning C++ is too hard to learn (and harder than C), when in fact, this couldn't be further from the truth.

String buffer = "data" // However, the Arduino String is a C++ class, and supports many MEMBER manipulation functions, ...

I agree C is much harder and less readable than C++ with all those classes. Even so I still write functional programs when using a c++ compiler although I use classes like String. There are lots of neat things you can do with C++ and it is well worth the effort if you want to become a real programmer. However my impression was that some just want to code a few simple hardware projects using Arduino C++ and that will teach the fundamentals of programming including using c++ classes like String.

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder

Posted by: @robotbuilder

@frogandtoad

There seems to be a very common misconception that learning C++ is too hard to learn (and harder than C), when in fact, this couldn't be further from the truth.

String buffer = "data" // However, the Arduino String is a C++ class, and supports many MEMBER manipulation functions, ...

Sure plain C is much harder and less readable than C++ compiler with all those classes. Even so I still write functional programs when using a c++ compiler although I use classes like String. There are lots of neat things you can do with C++ and it is well worth the effort if you want to become a real programmer. However my impression was that some just want to code a few simple hardware projects using Arduino C++.

 

Indeed... C++ was intended to alleviate the pain of C, specifically when using pointers and character arrays, and as such, I think C++ in just this small scope alone is well worth avoiding classic C.  However, once you increase your skills, and start using the ESP8288 and ESP32 for example, you have access to virtually the whole modern C++ Standard ISO library, which increases your personal power and skill by magnitudes, that would put a smile on anyone's face!

Under micro-controllers that offer good support, C++ offers dynamic arrays, maps, multimaps, sets, multisets, vectors, bitwise operatios, algorithms, templates, etc... I could go on and on, there is just so much it offers that if you're not using it, you're honestly missing out on the good things in programming and having fun doing it!

There are lots of neat things you can do with C++ and it is well worth the effort if you want to become a real programmer.

So, you think that only people who aspire to be real programmers would be interested in growing their skills? I can't say I agree with that, because I for one want to know about everything and make personal improvement, even if I know I'll never end up in that field.

However my impression was that some just want to code a few simple hardware projects using Arduino C++.

No doubt, this is true for some members, but not for others - We just can't paint them all with the same brush.

Cheers


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6963
 

@frogandtoad Totally agree re String is concerned, I always forget that because the C I used had that built in and there was no C++ available to us. I was referring to basics like if, else, do, while, where case etc. Learn K&R AND String first, then worry about C++ if you need to create your own class.

Now I learned something, I didn't know that String had all that functionality, BUT in the shortish time I have been playing with Arduino I haven't needed to in order to twiddle pins.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6963
 

@frogandtoad We will have to agree to disagree, I gave up on learning C++ because it was so complicated compared to C. If you think C++ is easier with more rules and syntax then our definitions of easy and hard are very different. Subject closed, we disagree. I will check out the String class though in case I ever encounter a need for any of it as so far I have not. I also welcome any more of your suggestions for generally/global use classes like String.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@frogandtoad 

 

@robotBuilder

There are lots of neat things you can do with C++ and it is well worth the effort if you want to become a real programmer.

So, you think that only people who aspire to be real programmers would be interested in growing their skills?

Instead of real programmer I meant professional programmer. I have been programming at a hobby level most of my life but have never put in the time or had the mathematical background to become professional. Professionals (including I suspect some that are self taught) have helped me at various times so I know how knowledgeable and practiced they are in the art.

I can't say I agree with that, because I for one want to know about everything and make personal improvement, even if I know I'll never end up in that field.

That is why in the next paragraph I wrote,

"However my impression was that some just want to code a few simple hardware projects using Arduino C++."

The Arduino C++ implementation is made to be easy for beginners to write programs to turn on LEDs or motors and read buttons and POTS and will teach them about numeric variables, strings, loops, conditional statements, functions and importing libraries. If they find they love the process of programming then maybe they might be motivated to dig deeper into the art.

 


   
Inst-Tech reacted
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@zander

Posted by: @zander

@frogandtoad Totally agree re String is concerned, I always forget that because the C I used had that built in and there was no C++ available to us.

I'm not sure what you used previously, but C never had and AFAIK, still does not have a built in string data type - All C strings are arrays.

Posted by: @zander

I was referring to basics like if, else, do, while, where case etc. Learn K&R AND String first, then worry about C++ if you need to create your own class.

I've mentioned this a number of times before - The C++ Standard library supports virtually the whole of the C Standard library, but I'll go further than that and say that conditional and iteration type statements are not unique to C... C++, C#, Java, PHP and others all use the same syntax, and every other programming language incorporates them, even if ever so slightly using a difference in syntax - These constructs are not a good reason to avoid a higher level language and its features.

Posted by: @zander

Now I learned something, I didn't know that String had all that functionality

You also forgot the 'Serial' object, the 'Servo' object, the 'Stepper' object, etc...  where would the newbie be without understanding these objects and there member functions?  To say you should learn C first, is like saying avoid these features, you can get to them later, which we all know is not the case, because all newbies in Arduino love to delve into these kind of projects first.

Cheers


   
ReplyQuote
Page 2 / 3