diff --git a/Spark_MDP/README.md b/Spark_MDP/README.md new file mode 100644 index 0000000..f17e3d2 --- /dev/null +++ b/Spark_MDP/README.md @@ -0,0 +1,63 @@ +# Multiple Digital Pins Library for MicroBlocks + +Welcome to the **MDP Library** for MicroBlocks! +This library makes it easy for anyone—even if you don’t know how to code or use a computer much—to control these modules: **RGB LED, Traffic Light,** and **Ultrasonic** using simple blocks in MicroBlocks. + +--- + +## Features + +- **Easy Drag-and-Drop Blocks** for controlling the module. +- **No Coding Required**. +- **Beginner-Friendly Instructions**. +- **Control the MDP Modules Easily**. + +--- + +## Getting Started + +**What you need:** +- Spark microcontroller and connecting wires. +- MicroBlocks IDE installed ([Download here](https://microblocks.fun/download/)). +- MDP Modules and basic connecting wires. + +--- + +## Installation + +1. **Download the MDP Library:** + Download the library file from [here](../Spark_MDP.ubl). + +2. **Open MicroBlocks IDE** on your computer. + +3. **Add the Library:** + - Go to the library manager in MicroBlocks. + - Click “Import Library” or drag and drop the downloaded file into the IDE. + +--- + +## How to Use + +1. **Connect your module** to your microcontroller’s pins (see your board’s pinout for details). + +2. **Open MicroBlocks IDE** and make sure your board is connected. + +3. **Find the MDP blocks** in the blocks menu. + +4. **Drag the blocks** you want to use into your script area. + +5. **Click the green flag** or “Run” to start controlling the module! + +--- +## Examples + +There is special examples for each module: + +- [**RGBLED**](../Spark_MDP/Spark_RGBLED/README.md) +- [**Traffic Light**](../Spark_MDP/Spark_TrafficLight/README.md) +- [**LEUltrasonicD**](../Spark_MDP/Spark_Ultrasonic/README.md) + +--- + +*Have fun building with Spark Kit!* + diff --git a/Spark_MDP/Spark_MDP.ubl b/Spark_MDP/Spark_MDP.ubl new file mode 100644 index 0000000..d28a735 --- /dev/null +++ b/Spark_MDP/Spark_MDP.ubl @@ -0,0 +1,58 @@ +module Spark_MDP 'cat;Variables' +author 'Fab Lab BH' +version 1 0 +description '' + + spec ' ' 'RGBLED3' 'RGBLED Pin _ R _ G _ B _' 'num num num auto' 17 50 50 50 + spec ' ' 'RGBLED3 Pin' 'RGBLED Pin _ R _ G _ B _' 'auto bool bool bool' 17 true true true + spec ' ' 'Traffic Light' 'Traffic Light Pin _ R _ Y _ G _' 'auto bool bool bool' 17 true true true + spec ' ' 'Traffic Light Pin' 'Traffic Light Pin _ R _ Y _ G _' 'num num num num' 17 255 255 255 + spec 'r' 'Ultrasonic Pin' 'Ultrasonic Pin _' 'num' 17 + +to RGBLED3 Pin Red Green Blue { + analogWriteOp Pin Red + analogWriteOp (Pin + 1) Green + analogWriteOp (Pin + 2) Blue +} + +to 'RGBLED3 Pin' Pin Red Green Blue { + digitalWriteOp Pin Red + digitalWriteOp (Pin + 1) Green + digitalWriteOp (Pin + 2) Blue +} + +to 'Traffic Light' Pin Red Yellow Green { + digitalWriteOp Pin Red + digitalWriteOp (Pin + 1) Yellow + digitalWriteOp (Pin + 2) Green +} + +to 'Traffic Light Pin' Pin Red Yellow Green { + analogWriteOp Pin Red + analogWriteOp (Pin + 1) Yellow + analogWriteOp (Pin + 2) Green +} + +to 'Ultrasonic Pin' Pin { + comment 'Contributed by Joan Guillén and Josep Ferràndiz' + digitalWriteOp (Pin + 1) false + waitMicros 2 + digitalWriteOp (Pin + 1) true + waitMicros 50 + digitalWriteOp (Pin + 1) false + local 'start' (microsOp) + waitUntil (or (not (digitalReadOp (Pin + 2))) (((microsOp) - start) > 23320)) + waitUntil (or (digitalReadOp (Pin + 2)) (((microsOp) - start) > 23320)) + if (((microsOp) - start) > 23320) { + comment 'Distance sensor not ready; return the last distance reading' + return _sr04_last + } + comment 'Pulse sent. Measure time until echo is detected.' + start = (microsOp) + waitUntil (or (not (digitalReadOp (Pin + 2))) (((microsOp) - start) > 23320)) + _sr04_last = ((10 * ((microsOp) - start)) / 583) + comment 'Leave some time for reverberations to die away.' + waitMillis 10 + return _sr04_last +} + diff --git a/Spark_MDP/Spark_RGBLED/Images/1.png b/Spark_MDP/Spark_RGBLED/Images/1.png new file mode 100644 index 0000000..5ad6ccc Binary files /dev/null and b/Spark_MDP/Spark_RGBLED/Images/1.png differ diff --git a/Spark_MDP/Spark_RGBLED/Images/2.png b/Spark_MDP/Spark_RGBLED/Images/2.png new file mode 100644 index 0000000..36b795c Binary files /dev/null and b/Spark_MDP/Spark_RGBLED/Images/2.png differ diff --git a/Spark_MDP/Spark_RGBLED/README.md b/Spark_MDP/Spark_RGBLED/README.md index e69de29..c5b87d0 100644 --- a/Spark_MDP/Spark_RGBLED/README.md +++ b/Spark_MDP/Spark_RGBLED/README.md @@ -0,0 +1,16 @@ +# RGB LED Versions +Displaying the version and its functions with examples. + +## Version 01 + +In these functions, you must specify the digital pin corresponding to the module you are using. + +![](Images/1.png) + +*Example 1* +This function takes three values, one for each color: Red, Green, and Blue. + +![](Images/2.png) + +*Example 2* +This function takes three values—one for Red, Green, and Blue—and also allows you to control the brightness of each. \ No newline at end of file diff --git a/Spark_MDP/Spark_TrafficLight/Images/1.png b/Spark_MDP/Spark_TrafficLight/Images/1.png new file mode 100644 index 0000000..9434d78 Binary files /dev/null and b/Spark_MDP/Spark_TrafficLight/Images/1.png differ diff --git a/Spark_MDP/Spark_TrafficLight/Images/2.png b/Spark_MDP/Spark_TrafficLight/Images/2.png new file mode 100644 index 0000000..1687ebe Binary files /dev/null and b/Spark_MDP/Spark_TrafficLight/Images/2.png differ diff --git a/Spark_MDP/Spark_TrafficLight/README.md b/Spark_MDP/Spark_TrafficLight/README.md index e69de29..0f65808 100644 --- a/Spark_MDP/Spark_TrafficLight/README.md +++ b/Spark_MDP/Spark_TrafficLight/README.md @@ -0,0 +1,16 @@ +# Traffic Light Versions +Displaying the version and its functions with examples. + +## Version 01 + +In these functions, you must specify the digital pin corresponding to the module you are using. + +![](Images/1.png) + +*Example 1* +This function takes three values, one for each color: Red, Yellow, and Green. + +![](Images/2.png) + +*Example 2* +This function takes three values—one for Red, Yellow, and Green—and also allows you to control the brightness of each. \ No newline at end of file diff --git a/Spark_MDP/Spark_Ultrasonic/Images/1.png b/Spark_MDP/Spark_Ultrasonic/Images/1.png index 07854e6..54c2ea5 100644 Binary files a/Spark_MDP/Spark_Ultrasonic/Images/1.png and b/Spark_MDP/Spark_Ultrasonic/Images/1.png differ diff --git a/Spark_MDP/Spark_Ultrasonic/README.md b/Spark_MDP/Spark_Ultrasonic/README.md index e69de29..2413812 100644 --- a/Spark_MDP/Spark_Ultrasonic/README.md +++ b/Spark_MDP/Spark_Ultrasonic/README.md @@ -0,0 +1,11 @@ +# Ultrasonic Versions +Displaying the version and its functions with examples. + +## Version 01 + +In this function, you must specify the MDP pin corresponding to the module you are using. + +![](../Spark_Ultrasonic/) + +*Example* +This function reads values from the pin and can be used inside an if-statement or assigned as a value. diff --git a/Spark_PWM/Spark_FanMotor/README.md b/Spark_PWM/Spark_FanMotor/README.md index 18f4a5a..83db387 100644 --- a/Spark_PWM/Spark_FanMotor/README.md +++ b/Spark_PWM/Spark_FanMotor/README.md @@ -3,7 +3,7 @@ Displaying the version and its functions with examples. ## Version 01 -In these functions, you must specify the I2C pin corresponding to the module you are using. +In these functions, you must specify the PWM pin corresponding to the module you are using. ![](Images/1.png) diff --git a/Spark_PWM/Spark_PWM.ubp b/Spark_PWM/Spark_PWM.ubp new file mode 100644 index 0000000..ca68b01 --- /dev/null +++ b/Spark_PWM/Spark_PWM.ubp @@ -0,0 +1,53 @@ +module main +author unknown +version 1 0 +description '' + + spec ' ' 'Fan Motor' 'Fan Motor Pin _ to Turn Off' 'num' 17 + spec ' ' 'Fan Motor Pin' 'Fan Motor Pin _ Direction _ Speed _' 'num bool auto' 17 true 50 + +to 'Fan Motor' Pin { + digitalWriteOp (Pin + 1) false + digitalWriteOp (Pin + 2) false +} + +to 'Fan Motor Pin' Pin Direction Speed { + if (and (Speed > 0) (Speed <= 100)) { + local 'PWM' (absoluteValue (((Speed - 1) * ((1023 - 1) / 99)) + 1)) + if (Direction == (booleanConstant false)) { + if (and (PWM > 0) (PWM < 1024)) { + digitalWriteOp (Pin + 1) true + analogWriteOp (Pin + 2) (1023 - PWM) + } + } else { + if (and (PWM > 0) (PWM < 1024)) { + digitalWriteOp (Pin + 1) false + analogWriteOp (Pin + 2) PWM + } + } + } +} + +script 50 168 { +to 'Fan Motor' {} +} + +script 66 341 { +to 'Fan Motor Pin' {} +} + + +module Spark_PWM Control +author 'Fab Lab' +version 1 0 +description '' + + spec ' ' 'FanMotor' 'FanMotor Pin _ Direction _ Speed _' 'num bool num' 17 true 50 + spec ' ' 'FanMotor2' 'FanMotor Pin _ to Turn Off' 'auto' 18 + +to FanMotor Pin Direction Speed { +} + +to FanMotor2 Pin { +} +