Zino logo Zino

Examples - Basic

Here you can find a lot of examples ready to be used in your applications. Enjoy 😎!


Analog Reading

#include <Arduino.h>
#include <Zino.h>

Pin analogSensorPin = Pin(PortC, 5);

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    Serial.println(
        GPIO::read(analogSensorPin)
    );
}

Blinky

#include <Arduino.h>
#include <Zino.h>

Blinky leds[4];

void setup()
{
    leds[0].init(Pin(PortB, 0), 600, 650);
    leds[1].init(Pin(PortB, 1), 700, 100);
    leds[2].init(Pin(PortB, 2), 300, 540);
    leds[3].init(Pin(PortB, 3), 100, 100);
}

void loop()
{
    for (int index = 0; index < 4; index++) {
        leds[index].refresh();
    }
}

Button

#include <Arduino.h>
#include <Zino.h>

Button button;

void buttonPressed()
{
    Serial.println("Button has been pressed 🤠");
}

void setup()
{
    Serial.begin(9600);
    button.init(Pin(PortB, 5), 40, false, false);
    button.pressed = buttonPressed;
}

void loop()
{
    button.refresh();
}

Button and Blinky

#include <Arduino.h>
#include <Zino.h>

Blinky leds[5];
Button button;

void buttonPressed()
{
    Serial.println("Button has been pressed 🔥");
}

void setup()
{
    Serial.begin(9600);

    button.init(Pin(PortB, 5), 40, false, false);
    button.pressed = buttonPressed;

    leds[0].init(Pin(PortB, 0), 600, 650);
    leds[1].init(Pin(PortB, 1), 700, 100);
    leds[2].init(Pin(PortB, 2), 300, 540);
    leds[3].init(Pin(PortB, 3), 100, 100);
    leds[4].init(Pin(PortB, 4), 450, 357);
}

void loop()
{
    for (int index = 0; index < 5; index++) {
        leds[index].refresh();
    }

    button.refresh();
}

Button and LED

#include <Arduino.h>
#include <Zino.h>

Button button;
LED led;

void buttonPressed()
{
    led.toggle();
    // Other methods 👇
    // led.on();
    // led.off();
}

void setup()
{
    button.init(Pin(PortB, 5), 40, false, false);
    button.pressed = buttonPressed;

    led.init(Pin(PortB, 4));
}

void loop()
{
    button.refresh();
}

Delay

#include <Arduino.h>
#include <Zino.h>

Delay myDelay;          // default duration 1000 ms.
// Delay myDelay(1000); //Other initialization

void callback()
{
    Serial.println("delay fired 🔥");
}

void setup()
{
    Serial.begin(9600);
    myDelay.init(500); //duration = 500 ms.

    myDelay.callback = callback;
}

void loop()
{
    myDelay.refresh();
    //Other stuff goes here
}

DC Motor

#include <Arduino.h>
#include <Zino.h>

DCMotor motor;

void setup()
{
    motor.init(Pin(PortB, 4), 200);
    motor.setDutyCycle(0.5); // controlling speed 
}

void loop()
{
    motor.refresh();
}

DC Motor and Potentiometer

#include <Arduino.h>
#include <Zino.h>

Pin potentiometer = Pin(PortC, 5);
DCMotor motor;

void setup()
{
    motor.init(Pin(PortB, 4), 150);
    motor.setDutyCycle(0);
}

void loop()
{
    double dutyCycle = double(GPIO::read(potentiometer)) / 1023; // 0.0 <-> 1.0

    motor.setDutyCycle(dutyCycle);
    motor.refresh();
}