Thread: Computers Nerd homework
View Single Post
Old 10-13-2021, 10:49 PM   #27
stanleychief stanleychief is offline
Veteran
 
stanleychief's Avatar
 

Join Date: Aug 2002
Location: Kansas City, MO
Casino cash: $5266254
Quote:
Originally Posted by phisherman View Post
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.
Posts: 1,193
stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.
Thumbs Up 1 Thumbs Down 0     Reply With Quote