From 85e978bbea3a6f4885a6a2457ba0895c51d81ef4 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Mon, 17 Feb 2025 17:04:31 +0100 Subject: [PATCH] put code block in collapsible box --- .../week_4_programming/programming.md | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/Assignments/week_4_programming/programming.md b/docs/Assignments/week_4_programming/programming.md index a236660..df7382d 100644 --- a/docs/Assignments/week_4_programming/programming.md +++ b/docs/Assignments/week_4_programming/programming.md @@ -338,30 +338,30 @@ Im going to map everything lower than 80 to 80 using software. The reason im doi Luckily there is an arduino function called `map` that can do this. [Source](https://docs.arduino.cc/language-reference/en/functions/math/map/). The syntax is like this `map(value, fromLow, fromHigh, toLow, toHigh)` so it's really easy to use. This is how I implemented it. During coding I realized this could be done way easier and simpler. So this is my result +??? code + ```cpp + #include -```cpp -#include + int pot1 = 0; + int Mpot1 = 0; //mapped pot -int pot1 = 0; -int Mpot1 = 0; //mapped pot + void setup(){ + Serial.begin(9600); + pinMode(0, INPUT); + } -void setup(){ - Serial.begin(9600); - pinMode(0, INPUT); -} - -void loop(){ - pot1 = analogRead(0); //store potmeter value in pot1 - - if (pot1 <= 80){ //check if pot1 is lower than 80, if yes make it 80 - Mpot1 = 80; - } - else { - Mpot1 = pot1; //if pot1 is above 80 just copy over pot1 to Mpot1 - } - Serial.println(Mpot1); -} -``` + void loop(){ + pot1 = analogRead(0); //store potmeter value in pot1 + + if (pot1 <= 80){ //check if pot1 is lower than 80, if yes make it 80 + Mpot1 = 80; + } + else { + Mpot1 = pot1; //if pot1 is above 80 just copy over pot1 to Mpot1 + } + Serial.println(Mpot1); + } + ``` This code works and makes any value under 80 automatically 80. And keeps all values above the original value. I've cleaned it up a bit and turned it into a function so I don't have to copy paste code later on and so it stays clean.