Topics
- RC cars transistor control
- Passing pointers to functions
RC cars transistor control
Moving along, I tried to tackle this problem using a more intuitive understanding of the components. I forced myself to rewrite the code without looking back at examples from previous labs. I had noticed a tendency to copy bits and pieces from previous labs, something I feel was hampering my education. Not including the parallel branch with the capacitor, diode, and motor (which was new), I added components to the board by first explaining to myself what the part would do. This intuitive approach also guided my code. I know what a transistor works now so I worked through the logic of what I would need to connect and apply a voltage at the gate. The pot was on it's own little island and used to grab values.
I had the code written and thought I should have worked. Alas, my motor would spin at a generally constant speed regardless of what I was doing. After some debugging I realized it was probably a component. I completely disconnected the base of the transistor and (BINGO) the wheels still spun. Edgar gave me a new transistor and that solved my problem.
Passing pointers to functions
Finally we have landed on the part of pointers that seems interesting and useful. While we had been spending time working out the logic of how pointers work, Now we have a way to write functions that don't need to assume we have the correct variable declared because we can use pointers in the function and direct them to the arguments of the function.
The first modification required of us was to take in the threshold values from the user and check them for consistency with the program. I made a function and feed in pointer arguments.
Soldiering on, I made the second modification, which was rather simple. Adding a variable, NumEvents, and setting it to zero, then incrementing NumEvents inside the if loop where an event is detected. Lastly, I print the value of the NumEvents once the file has been closed.
Although I am unable to to check this part of the code because of the file problem, I don't anticipate any problem with this simple modification.









