My son needs help with his homework and I know nothing about coding , he is trying to get a RGB strip to light up with increasing intensity as more pressure is applied to sensor while also randomizing a series of colors .(llike a light up shoe)
this is what he has which he knows is horribly wrong i am pretty sure this is C/C+, this is his hisrt ever coding class so his knowledge is fairly limited.
I also know it is in french but it might still make sense to some of you
int valeur1 = 0; //variable de type integer pour enregistrer analog A0
int valeur2 = 0; //variable de type integer pour enregistrer analog A0
int valeur3 = 0;
int valeur4 = 0;
int valeur5 = 0;
void setup() {
Serial.begin(9600); //commence le serial pour ecrire les données
pinMode(A0,INPUT_PULLUP); //prepare A0 pour le pressure sensor
pinMode(3,OUTPUT); //prepare pin 3 pour output de 5V
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
Originally Posted by stanleychief:
I just hope this kid renames the variables before turning in the code. If I were grading the assignment, I'd be raising an eyebrow if the variables were French. :-)
I once worked on some client's code, which was apparently written by a guy named Eric. Every variable in his code was prefixed with 'eric'. So the SQL DB connection was 'ericDbConn', and the result set was 'ericDbResult', the datarow object was 'ericDbRow', etc.
I thought that was pretty damned hilarious!
What was this piece of code written for, if I may ask? [Reply]
Apparently it's been awhile since I dipped my toe in C world so I'll just say make the code more linear and unless he's coding for a French person use the English Language for comments. [Reply]
Originally Posted by ptlyon:
What was this piece of code written for, if I may ask?
It was a long time ago, but I believe that particular code was embedded in a classic ASP page. He was fetching options from the database to populate a select tag on a form.
I recall that the guy left a lot of comments too, which is usually a good thing, but his comments were unnecessary, as they didn't explain anything helpful. Example:
Code:
// This is the database connection
Dim ericDbConn = Server.CreateObject("ADODB.Connection")
Pretty obvious, given the naming, and straight-forward variable assignment. Struck me as if they were written by someone just out of school. The client was a large regional grocery store chain. [Reply]
Originally Posted by stanleychief:
It was a long time ago, but I believe that particular code was embedded in a classic ASP page. He was fetching options from the database to populate a select tag on a form.
I recall that the guy left a lot of comments too, which is usually a good thing, but his comments were unnecessary, as they didn't explain anything helpful. Example:
Code:
// This is the database connection
Dim ericDbConn = Server.CreateObject("ADODB.Connection")
Pretty obvious, given the naming, and straight-forward variable assignment. Struck me as if they were written by someone just out of school. The client was a large regional grocery store chain.
That was my first thought as well. Naming conventions have always been my downfall. I've learned some, but still sometimes go back to what makes sense to me at the time. [Reply]
Originally Posted by ptlyon:
That was my first thought as well. Naming conventions have always been my downfall. I've learned some, but still sometimes go back to what makes sense to me at the time.
There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton
Apparently it's been awhile since I dipped my toe in C world so I'll just say make the code more linear and unless he's coding for a French person use the English Language for comments.
French Highschool so the French is mandatory , it sucks lol. [Reply]
Well he managed to figure it out , he says it worked like it was supposed to but he said he didn't code it like the teacher did , he said the tips in here were helpful.
Originally Posted by Monticore:
French Highschool so the French is mandatory , it sucks lol.
Oh, completely missed that! I assumed that he found an example of the code in French and was trying to use it in an English computer science class. He should probably keep those variable names in French then. :-)
Glad to hear that this helped. Is your son looking to pursue a career in computer science, or is this just one of his classes? Programming can be intimidating at first, but if he sticks with it, things will become easier. All that gibberish starts to make sense at some point. [Reply]
Originally Posted by stanleychief:
Oh, completely missed that! I assumed that he found an example of the code in French and was trying to use it in an English computer science class. He should probably keep those variable names in French then. :-)
Glad to hear that this helped. Is your son looking to pursue a career in computer science, or is this just one of his classes? Programming can be intimidating at first, but if he sticks with it, things will become easier. All that gibberish starts to make sense at some point.
I recommended he try it out since he always liked the idea of maybe getting into robotics , he is very strong in math, physics and chemistry and likes problem solving ,unfortunately it is a subject my wife or I can't help much with , he just procrastinated a bit and was getting flustered and was hoping a tip or two might get him back on the right track which it did. [Reply]
Not sure how many more labs he will have, but here's a piece of advice our instructors gave us.
When you're trying to work out a problem with your code, step away. Do something else, get your mind off of it. Sometimes clearing your mind will bring you the answer.
Also when you go to bed, put a pad and pen next to your bed. You would be surprised how many times that worked for me, waking up with either an answer to a problem or an idea of how to write a program in the middle of the night.
Originally Posted by ptlyon:
Not sure how many more labs he will have, but here's a piece of advice our instructors gave us.
When you're trying to work out a problem with your code, step away. Do something else, get your mind off of it. Sometimes clearing your mind will bring you the answer.
Also when you go to bed, put a pad and pen next to your bed. You would be surprised how many times that worked for me, waking up with either an answer to a problem or an idea of how to write a program in the middle of the night.
Good luck.
Exactly what I was trying to explain to him last night , he is still young and stubborn he will learn. [Reply]