ChiefsPlanet Mobile
Page 4 of 4
< 1234
The Meltdown Lounge>Nerd homework
Monticore 08:27 PM 10-13-2021
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);
}

void loop() {

valeur1 = analogRead(A0);
delay(1000);
valeur2 = (200/valeur1);
valeur3 = (valeur2*valeur2);




valeur4 = random(255);
valeur5 = valeur4;

if (valeur4 > valeur5){
valeur5--;
analogWrite(3,valeur5);

}

if (valeur4 < valeur5){
valeur5++;
analogWrite(3,valeur5);

}

if (valeur4 == valeur5){

valeur5;
analogWrite(3,valeur5);

}







if (valeur4 > valeur5){
valeur5++;
analogWrite(5,valeur5);

}

if (valeur4 < valeur5){
valeur5--;
analogWrite(5,valeur5);

}

if (valeur4 == valeur5){

analogWrite(5,valeur5);

}








if (valeur4 > valeur1){
valeur5++;
analogWrite(6,valeur5);

}

if (valeur4 < valeur5){
valeur5--;
analogWrite(6,valeur5);

}

if (valeur4 == valeur5){

analogWrite(6,valeur5);

}

}

would appreciate any help or insults
[Reply]
ptlyon 11:18 AM 10-14-2021
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]
Otter 11:21 AM 10-14-2021
Curly brackets?

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]
stanleychief 11:32 AM 10-14-2021
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]
ptlyon 11:38 AM 10-14-2021
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]
stanleychief 11:44 AM 10-14-2021
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

https://martinfowler.com/bliki/TwoHardThings.html
[Reply]
Monticore 11:53 AM 10-14-2021
Originally Posted by Otter:
Curly brackets?

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]
Monticore 11:56 AM 10-14-2021
Originally Posted by stanleychief:
There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton

https://martinfowler.com/bliki/TwoHardThings.html
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.

thanks fellas .
[Reply]
stanleychief 12:03 PM 10-14-2021
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]
Monticore 12:20 PM 10-14-2021
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]
ptlyon 12:41 PM 10-14-2021
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.
[Reply]
Monticore 12:55 PM 10-14-2021
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]
Page 4 of 4
< 1234
Up