aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-01 22:18:26 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-01 22:18:26 +0200
commit223894c7305a084130edfba75108c87b2c453691 (patch)
tree24c6110430cabc81c27584425e5fcca51c4e387b
parentaaf35ec4d317224b6fa9a226479f0d56fc266eb0 (diff)
add library as appendix; add diagrams to library; drop individual mussel sketches
-rw-r--r--Mussel/Mussel_begin.puml10
-rw-r--r--Mussel/Mussel_read.puml10
-rw-r--r--Mussel/examples/seconds/seconds.puml16
-rw-r--r--mussel1/mussel1.ino25
-rw-r--r--mussel1/mussel1.puml20
-rw-r--r--mussel2/mussel2.ino25
-rw-r--r--mussel2/mussel2.puml20
-rw-r--r--mussel3/mussel3.ino46
-rw-r--r--mussel4/mussel4.ino32
-rw-r--r--mussel5/mussel5.ino74
-rw-r--r--mussel6/mussel6.ino27
-rw-r--r--report.qmd55
12 files changed, 61 insertions, 299 deletions
diff --git a/Mussel/Mussel_begin.puml b/Mussel/Mussel_begin.puml
new file mode 100644
index 0000000..17fb9fa
--- /dev/null
+++ b/Mussel/Mussel_begin.puml
@@ -0,0 +1,10 @@
+@startuml
+start
+if (type ?) equals (defined) then
+:init sensor driver;
+endif
+if (pin ?) equals (defined) then
+:configure input pin;
+endif
+stop
+@enduml
diff --git a/Mussel/Mussel_read.puml b/Mussel/Mussel_read.puml
new file mode 100644
index 0000000..d0bea40
--- /dev/null
+++ b/Mussel/Mussel_read.puml
@@ -0,0 +1,10 @@
+@startuml
+start
+:set time to current second;
+if (time mod 12 ?) equals (< 9) then
+:set gape to "42";
+else (>= 9)
+:set gape to "2";
+endif
+stop
+@enduml
diff --git a/Mussel/examples/seconds/seconds.puml b/Mussel/examples/seconds/seconds.puml
new file mode 100644
index 0000000..578983c
--- /dev/null
+++ b/Mussel/examples/seconds/seconds.puml
@@ -0,0 +1,16 @@
+@startuml
+'start
+:instantiate object;
+group init
+:activate object;
+:fetch and print object description;
+end group
+while (repeat every few millisecond)
+group loop {
+:fetch and print gape angle;
+:wait 1s;
+end group
+endwhile
+-[hidden]->
+kill
+@enduml
diff --git a/mussel1/mussel1.ino b/mussel1/mussel1.ino
deleted file mode 100644
index 7fac523..0000000
--- a/mussel1/mussel1.ino
+++ /dev/null
@@ -1,25 +0,0 @@
-/// mussel1 - mussel voter influenced by time
-///
-/// SPDX-License-Identifier: GPL-3.0-or-later
-/// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
-
-#define MUSSEL_ATTITUDE "closed 10 seconds every 50 seconds"
-
-void setup() {
- Serial.begin(115200);
- Serial.printf("\n\nDevice ready: %s\n",
- MUSSEL_ATTITUDE);
-}
-
-void loop() {
- Serial.printf("gap:%d\n", read());
-
- delay(1000);
-}
-
-byte read() {
- // return 42 if current second modulo 60 is below 50, else 2
- return (byte) (((unsigned long)millis() / 1000) % 60) < 50
- ? 42
- : 2;
-}
diff --git a/mussel1/mussel1.puml b/mussel1/mussel1.puml
deleted file mode 100644
index dda8ac7..0000000
--- a/mussel1/mussel1.puml
+++ /dev/null
@@ -1,20 +0,0 @@
-@startuml
-start
-partition init {
-:setup serial connection;
-:print "ready";
-}
-while (repeat every few millisecond)
-partition loop {
-:resolve currentSecond;
-if (currentSecond < 50 ?) equals (yes) then
-:print "good";
-else (no)
-:print "bad";
-endif
-:wait 1s;
-}
-endwhile
--[hidden]->
-kill
-@enduml
diff --git a/mussel2/mussel2.ino b/mussel2/mussel2.ino
deleted file mode 100644
index 90d8a47..0000000
--- a/mussel2/mussel2.ino
+++ /dev/null
@@ -1,25 +0,0 @@
-/// mussel2 - mussel voter influenced by time
-///
-/// SPDX-License-Identifier: GPL-3.0-or-later
-/// SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
-
-#define MUSSEL_ATTITUDE "closed 4 seconds every 8 seconds"
-
-void setup() {
- Serial.begin(115200);
- Serial.printf("\n\nDevice ready: %s\n",
- MUSSEL_ATTITUDE);
-}
-
-void loop() {
- Serial.printf("gap:%d\n", read());
-
- delay(1000);
-}
-
-byte read() {
- // return 42 if current second modulo 12 is below 9, else 2
- return (byte) (((unsigned long)millis() / 1000) % 12) < 9
- ? 42
- : 2;
-}
diff --git a/mussel2/mussel2.puml b/mussel2/mussel2.puml
deleted file mode 100644
index 115d505..0000000
--- a/mussel2/mussel2.puml
+++ /dev/null
@@ -1,20 +0,0 @@
-@startuml
-start
-partition init {
-:setup serial connection;
-:print "ready";
-}
-while (repeat every few millisecond)
-partition loop {
-:resolve currentSecond;
-if (currentSecond mod 12 < 9 ?) equals (yes) then
-:print "good";
-else (no)
-:print "bad";
-endif
-:wait 1s;
-}
-endwhile
--[hidden]->
-kill
-@enduml
diff --git a/mussel3/mussel3.ino b/mussel3/mussel3.ino
deleted file mode 100644
index 0777b01..0000000
--- a/mussel3/mussel3.ino
+++ /dev/null
@@ -1,46 +0,0 @@
-/// mussel3 - mussel voter influenced by Humidity
-///
-/// SPDX-License-Identifier: GPL-3.0-or-later
-/// SPDX-FileCopyrightText: 2025 Noor Ahmad <noora@ruc.dk>
-
-
-#include <DHT.h>
-#include <Arduino.h>
-
-
-#define DHTPIN 15 // Digital pin connected to the DHT sensor - red
-#define DHTTYPE DHT11
-#define ESC_SIGNAL_PIN 19 //white
-DHT dht(DHTPIN, DHTTYPE);
-
-
-void setup() {
- Serial.begin(9600);
- dht.begin();
-}
-
-void loop() {
- // Wait a few seconds between measurements
- delay(1000);
-
- vote();
-
-
-
- delay(1000); // Delay between sensor readings
-}
-void vote() {
-
- float temperature = dht.readTemperature(); // Read temperature as Celsius
-
- // Print temperature
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println("°C");
-
- int lightValue = analogRead(34); // GPIO34 (analog pin) - blue
-
- // Print the light sensor value to Serial Monitor
- Serial.print("Light Sensor Value: ");
- Serial.println(lightValue);
-} \ No newline at end of file
diff --git a/mussel4/mussel4.ino b/mussel4/mussel4.ino
deleted file mode 100644
index c84f19b..0000000
--- a/mussel4/mussel4.ino
+++ /dev/null
@@ -1,32 +0,0 @@
-// I've been inspired by this page and the accompanying yt-video (among other videos), but unfortunatly i felt like bits of it were off https://roboticsbackend.com/arduino-push-button-tutorial/
-// So therefore I've tried to incoorporate more from my earlier p5 programs, but i'm unsure if this is right/wrong as well, as i'm having trouble with getting my arduionoboard to react to anything.
-// the idea is, that when the button is pushed down, it symbolizes thtat the mussel has closed it's mouth
-
-
-const int button = 4; // jeg har oprettet en konstant variabel, som har værdien 4 fordi den er forbundet til GPIO4 på arduinoboardet.
- //Den er konstant, fordi værdien ikke skal ændres mens programmet er i brug/kører
-void setup() { //den her del har jeg valgt bare at acceptere - den initialisere "serial commuication" og konfigurere(opsætter) de forskellige komponenter,
- //der bruges i programmet https://arduinofactory.com/arduino-ide/ , med andre ord, kridter den banen op.
- Serial.begin(9600); // starter kommunikationen mellem ard.boardet og computeren. tallet er baudraten, som data sendes med (hastigheden)
- pinMode(buttonPin, INPUT_PULLDOWN); // pinMode bestemmer hvilken GPIO-pin, som arduionoB. bruger.
- // input_pulldown er det, som sørger for, at programmet kun reagere når knappen bliver trykket ned. Altså at knappen som standard LOW.
- //det her har jeg valgt fremfor yt-tutorialsenes opfordring om, at bruge PULLUP, for så kommer der et svar *efter, og ikke imens brugeren trykker.
-}
-
-void loop(){ // void loop er en funktion, hvor alt indeni gentages så længe ard.boardet er tændt.
- int buttonState = digitalRead(buttonPIn); // læser knappens tilstand
-
- if (buttonState == HIGH) {
- Serial.println("Mussel has closed. Water might be contaminated.")
- } else {
- Serial.println("Mussel remains open. No detection made.");
- }
- delay(100); //her venter programmet 100 millisekunder, før den gentager loopet (altså går tilbage til standard, not contaminated)
- // jeg ved ikke helt om det er for kort tid, fordi min ard.board er i udu (eller jeg har svært ved at bruge det i guess)
-
-}
-
-
-
-
-
diff --git a/mussel5/mussel5.ino b/mussel5/mussel5.ino
deleted file mode 100644
index 12f42d6..0000000
--- a/mussel5/mussel5.ino
+++ /dev/null
@@ -1,74 +0,0 @@
-/// mussel_mood.ino - Button-controlled LED system with state tracking
-///
-/// SPDX-License-Identifier: GPL-3.0-or-later
-/// SPDX-FileCopyrightText: 2025 Tanishka Suwalka <tanishkas@ruc.dk>
-///
-/// This code toggles LEDs based on button presses, cycling through Red, Green, and Yellow states.
-
-const int buttonPin = 9;
-const int redLED = 3;
-const int greenLED = 4;
-const int yellowLED = 5;
-
-int buttonState = HIGH;
-int lastButtonState = HIGH;
-int clickCount = 0;
-unsigned long lastDebounceTime = 0;
-const unsigned long debounceDelay = 50;
-
-void setup() {
- pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up resistor for button
- pinMode(redLED, OUTPUT);
- pinMode(greenLED, OUTPUT);
- pinMode(yellowLED, OUTPUT);
- Serial.begin(9600); // Initialize serial monitor for debugging
-}
-
-void loop() {
- int reading = digitalRead(buttonPin); // Read button state
-
- // Debounce logic: Ensures a single press isn't detected multiple times
- if (reading != lastButtonState) {
- lastDebounceTime = millis(); // Reset debounce timer
- }
-
- if ((millis() - lastDebounceTime) > debounceDelay) {
- // Check for button press (transition from HIGH to LOW)
- if (reading == LOW && lastButtonState == HIGH) {
- clickCount++; // Increment click count
- if (clickCount > 3) {
- clickCount = 0; // Reset cycle after 3 clicks
- }
- updateLEDs();
- }
- }
-
- lastButtonState = reading; // Update button state
-}
-
-/// updateLEDs() - Updates LED states based on click count
-void updateLEDs() {
- // Turn off all LEDs first
- digitalWrite(redLED, LOW);
- digitalWrite(greenLED, LOW);
- digitalWrite(yellowLED, LOW);
-
- // Determine which LED to turn on
- switch (clickCount) {
- case 1:
- digitalWrite(redLED, HIGH);
- Serial.println("State: Angry (Red LED ON)");
- break;
- case 2:
- digitalWrite(greenLED, HIGH);
- Serial.println("State: Happy (Green LED ON)");
- break;
- case 3:
- digitalWrite(yellowLED, HIGH);
- Serial.println("State: Unsure (Yellow LED ON)");
- break;
- case 0:
- Serial.println("State: Off (All LEDs OFF)");
- break;
- }
-}
diff --git a/mussel6/mussel6.ino b/mussel6/mussel6.ino
deleted file mode 100644
index 0886a4a..0000000
--- a/mussel6/mussel6.ino
+++ /dev/null
@@ -1,27 +0,0 @@
-const int ledPin = 13; // LED connected to digital pin 13
-
-void setup() {
- pinMode(ledPin, OUTPUT);
- Serial.begin(9600);
- Serial.println("Enter 'ON' to turn the LED on, or 'OFF' to turn it off.");
-}
-
-void loop() {
- if (Serial.available() > 0) {
- String command = Serial.readStringUntil('\n');
- command.trim();
-
- if (command.equalsIgnoreCase("ON")) {
- digitalWrite(ledPin, HIGH);
- Serial.println("LED is now ON.");
- }
- else if (command.equalsIgnoreCase("OFF")) {
- digitalWrite(ledPin, LOW);
- Serial.println("LED is now OFF.");
- }
- else {
- Serial.println("Invalid command. Please type 'ON' or 'OFF'.");
- }
- }
-}
-
diff --git a/report.qmd b/report.qmd
index 42df97a..c9bb64a 100644
--- a/report.qmd
+++ b/report.qmd
@@ -86,8 +86,26 @@ TODO
# Description of the Program
+Use of the library in a sketch...
+
+```{.plantuml}
+!include Mussel/examples/seconds/seconds.puml
+```
+
TODO
+## Library function `begin()`
+
+```{.plantuml}
+!include Mussel/Mussel_begin.puml
+```
+
+## Library function `read()`
+
+```{.plantuml}
+!include Mussel/Mussel_read.puml
+```
+
# User Guide
TODO
@@ -114,42 +132,19 @@ TODO
\appendix
-# Arduino project code {.appendix}
-
-## mussel 1
-
-```{.plantuml}
-!include mussel1/mussel1.puml
-```
-
-```{.c include="mussel1/mussel1.ino" code-line-numbers="true"}
-```
-
-## mussel 2
-
-```{.plantuml}
-!include mussel2/mussel2.puml
-```
-
-```{.c include="mussel2/mussel2.ino" code-line-numbers="true"}
-```
-
-## mussel 3
-
-```{.c include="mussel3/mussel3.ino" code-line-numbers="true"}
-```
+# Mussel library {.appendix}
-## mussel 4
+## Headers
-```{.c include="mussel4/mussel4.ino" code-line-numbers="true"}
+```{.c include="Mussel/Mussel.h" code-line-numbers="true"}
```
-## mussel 5
+## Source code
-```{.c include="mussel5/mussel5.ino" code-line-numbers="true"}
+```{.c include="Mussel/Mussel.cpp" code-line-numbers="true"}
```
-## mussel 6
+## Example sketch
-```{.c include="mussel6/mussel6.ino" code-line-numbers="true"}
+```{.c include="Mussel/examples/seconds/seconds.ino" code-line-numbers="true"}
```