ChiefsPlanet Mobile
Page 2 of 4
< 12 34 >
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]
Beef Supreme 09:12 PM 10-13-2021
Have you tried turning it off and back on again?
[Reply]
Monticore 09:14 PM 10-13-2021
Originally Posted by phisherman:
It would help to see the formal requirements of the assignment.
it would all be in french lol , he needs the strip to light up in random rbg colors while also increasing in intensity of brightness equal to pressure on a sensor, he can do both tasks separately .
[Reply]
ptlyon 09:17 PM 10-13-2021
Wtf is a Ruth Bader ginsberg color?
[Reply]
Fish 09:47 PM 10-13-2021
Needs a lot of additional information. No offense, but it kinda looks like your son found a bit of code online and is trying to work backwards without knowing what it means. The code just declares some variable values, but a lot seems to be missing to actually do much of anything. Would need more info on what RGB board model he's using and so on.
[Reply]
cdcox 10:00 PM 10-13-2021
He shouldn’t try to write the entire code all at once. It can be too hard to hold the whole logic flow in his head all at once, even for a small problem like this. Instead, he should break it down into simpler projects that will contribute to the larger solution.

1. Turn an rgb strip on.
2. Make an rgb strip show random colors.
3. Make an rgb strip turn on only when the touch pad is touched.
4. Make an rgb strip intensity responsive to pressure.
5. Combine 2 and 4. Done.

This process of breaking problems down into smaller manageable parts and then composing the big solution from smaller solutions is a very important skill for engineering or software. As a budding engineer, he should focus on one tiny task in isolation of the others and just keep pounding on it until he gets a breakthrough. Most likely he will find the activity of solving small problems all consuming.

This will be the process he follows his entire career. If he tries to grapple with the big problem all at once, it can get confusing and frustrating very fast. Imagine trying to design a whole commercial airplane all at once. Every engineer breaks complicated problems into smaller, manageable parts and knocks them down one at a time.
[Reply]
Monticore 10:19 PM 10-13-2021
Originally Posted by Fish:
Needs a lot of additional information. No offense, but it kinda looks like your son found a bit of code online and is trying to work backwards without knowing what it means. The code just declares some variable values, but a lot seems to be missing to actually do much of anything. Would need more info on what RGB board model he's using and so on.
Ya i figure he is missing something but think they never covered it in class so he is just lost and going around in circles, everything else at school comes easy so he is getting frustrated and doesn't want to step away /get sleep etc.. and try later.

It is arduino uno is the item he is working with.
[Reply]
Bearcat 10:19 PM 10-13-2021
Originally Posted by cdcox:
He shouldn’t try to write the entire code all at once. It can be too hard to hold the whole logic flow in his head all at once, even for a small problem like this. Instead, he should break it down into simpler projects that will contribute to the larger solution.

1. Turn an rgb strip on.
2. Make an rgb strip show random colors.
3. Make an rgb strip turn on only when the touch pad is touched.
4. Make an rgb strip intensity responsive to pressure.
5. Combine 2 and 4. Done.

This process of breaking problems down into smaller manageable parts and then composing the big solution from smaller solutions is a very important skill for engineering or software. As a budding engineer, he should focus on one tiny task in isolation of the others and just keep pounding on it until he gets a breakthrough. Most likely he will find the activity of solving small problems all consuming.

This will be the process he follows his entire career. If he tries to grapple with the big problem all at once, it can get confusing and frustrating very fast. Imagine trying to design a whole commercial airplane all at once. Every engineer breaks complicated problems into smaller, manageable parts and knocks them down one at a time.
Exactly. And he wouldn't believe how minuscule the problem can be in programming, and if you write a bunch of code, you're basically doing what Fish said and trying to reverse-engineer it.

I learned this in college when I'd write a bunch of code, then would get so frustrated with it I'd start deleting shit until I found the dumbest bullshit ever that I would have found if I had only written the first few lines and tested.

I would also suggest outputting status and variables along the way... so when he sets valeur4 to a random number, add a line to echo that so you know what that value is, and then in the first if statement, have it output "in the first if statement", valeur4=(whatever), valeur5=(whatever).... to ensure it's doing what you expect it to as you follow the wisdom above and go step by step.
[Reply]
stanleychief 10:20 PM 10-13-2021
I'm guessing this is an Arduino 'Sketch' script. Reference for that language syntax can be found here: https://www.arduino.cc/reference/en/ in English even! And yes, it's basically C++ with a little special sauce added in.
[Reply]
Monticore 10:20 PM 10-13-2021
Originally Posted by cdcox:
He shouldn’t try to write the entire code all at once. It can be too hard to hold the whole logic flow in his head all at once, even for a small problem like this. Instead, he should break it down into simpler projects that will contribute to the larger solution.

1. Turn an rgb strip on.
2. Make an rgb strip show random colors.
3. Make an rgb strip turn on only when the touch pad is touched.
4. Make an rgb strip intensity responsive to pressure.
5. Combine 2 and 4. Done.

This process of breaking problems down into smaller manageable parts and then composing the big solution from smaller solutions is a very important skill for engineering or software. As a budding engineer, he should focus on one tiny task in isolation of the others and just keep pounding on it until he gets a breakthrough. Most likely he will find the activity of solving small problems all consuming.

This will be the process he follows his entire career. If he tries to grapple with the big problem all at once, it can get confusing and frustrating very fast. Imagine trying to design a whole commercial airplane all at once. Every engineer breaks complicated problems into smaller, manageable parts and knocks them down one at a time.
he just doesn't know how to combine it i think he can't make it do the rest.
[Reply]
Bearcat 10:23 PM 10-13-2021
Originally Posted by arrwheader:
Also he has val 5 equals val 4 and then is comparing them in the if statements? They are the same.


Sent from my Pixel 3a using Tapatalk
And this is a good place to start, as he sets them equal to each other and then never does anything to change their values.... so, a good start would be to echo all of the variables after their set, so you know what they are, then do the same within the if statements so he can see exactly what the program is doing.
[Reply]
phisherman 10:32 PM 10-13-2021
Originally Posted by Monticore:
he just doesn't know how to combine it i think he can't make it do the rest.
The point about this though is that when dealing with programming, you sub divide the problem into smaller chunks to solve. This is the bedrock of object oriented programming.

Disclaimer, I didn't stay at a Holiday Inn Express last night but I have taught object oriented programming at a state university for almost 10 years.
[Reply]
stanleychief 10:49 PM 10-13-2021
Originally Posted by phisherman:
The point about this though is that when dealing with programming, you sub divide the problem into smaller chunks to solve. This is the bedrock of object oriented programming.

Disclaimer, I didn't stay at a Holiday Inn Express last night but I have taught object oriented programming at a state university for almost 10 years.
Very true for the real world. For Arduino sketches though, it's pretty simplified. OO design here would likely be overkill. For a sketch file, you essentially have two methods that execute: setup and loop.

In setup, you initialize your variables, pins, etc. In loop, you put in the code that will repeatedly execute in a loop.

Considering the stated objectives, I'd solve the problem in the loop code like so:

* Read the pressure sensor value and convert that to a decimal value between 0 and 1.
* Generate random values for red, green and blue LEDs and store those values into three variables.
* Multiply each of those three variables by the converted pressure sensor value.
* Write the three values to the RGB LED output pins.
[Reply]
cdcox 11:00 PM 10-13-2021
Originally Posted by Monticore:
he just doesn't know how to combine it i think he can't make it do the rest.
Make him show you a working version of 2 and 4. I suspect he does not have those yet. Once he has those working, it is a matter of when he turns on and modulates the light in project 4, he inserts the code from project 2 that modulates its color.

I have been programming on a regular basis for more than 40 years. I built from scratch a website that contains more than 30,000 lines of code. Even with my experience, when I started fiddling with arduino boards (which sounds like what your son is working with) a few years ago out of curiosity, I would have broken the problem your son is working on now into these tiny mini projects.

Literally some of the first things I did with the arduino were to turn on an led, turn on an led with a switch, turn on an led for random periods of time, etc. My goal project was to time how long it took for weighing lever to tip using an accelerometer, and combine that information from a level sensor to calculate the velocity of water flow in a channel. This had nothing to do with leds being on or off. But because I was working in a new ecosystem, I started with the most basic of baby steps. When I built my goal project, it involved maybe half a dozen sub projects along the way. When I fully understood each sub project, composing them into the final project was fairly easy because of the familiarity I had built up working on the sub projects.
[Reply]
stanleychief 11:42 PM 10-13-2021
Lots of good advice here. I think cdcox and I may have a lot in common. I too have been programming for a long time. Started at 14 yrs old on an Atari 800. That was a few years ago!

Ok, so I dug out my last ESP32 project. If you are using the Arduino IDE, which I would assume you are, you can print variable values to the console by using "Serial.println()". So for instance, if you are trying to see what the actual value of your pressure sensor is, you could do something like this:

Code:
pressureValue = analogRead(A0);
Serial.println(pressureValue);
When I get some down time, and my other hobbies are on hold, I like to tackle IoT projects. A while back, I was doing some prototype work with an ESP32 LyraT board. I wrote an iOS app that would communicate with the board using BLE (low energy bluetooth), prompt the user to select a Wifi SSID, take in the password, and hand that off to the ESP32 board. From there the board would join the Wifi network and initiate a SIP session with a remote VOIP provider. Pressing a button on the ESP32 would initate a SIP voice call to a predetermined number from the device. Essentially, the ESP32 LyraT would become a SIP phone at that point.
[Reply]
Monticore 04:33 AM 10-14-2021
Appreciate the help guys , not sure if he figured it out i went to bed but will let you know
[Reply]
Page 2 of 4
< 12 34 >
Up