Skip to content

Commit

Permalink
initial version (#1)
Browse files Browse the repository at this point in the history
* initial release
  • Loading branch information
RobTillaart authored Oct 14, 2022
1 parent 4de8c41 commit 76ab0f1
Show file tree
Hide file tree
Showing 18 changed files with 800 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
# Choosing to run compilation tests on 2 different Arduino platforms
# selected only those that work
platforms:
- uno
# - due
# - zero
# - leonardo
# - m4
# - esp32
# - esp8266
# - mega2560
- rpipico

libraries:
- "Servo"
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: RobTillaart

13 changes: 13 additions & 0 deletions .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

name: Arduino-lint

on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict
17 changes: 17 additions & 0 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Arduino CI

on: [push, pull_request]

jobs:
runTest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb
18 changes: 18 additions & 0 deletions .github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: JSON check

on:
push:
paths:
- '**.json'
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Change Log PERIPUMP

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.1.0] - 2022-10-13

- initial version
- add stop(), get- and setpercentage()
- add getSeconds(), resetSeconds() for simple duration management.
- low percentages < 50% do not work.


2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Rob Tillaart
Copyright (c) 2022-2022 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
100 changes: 100 additions & 0 deletions PERIPUMP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// FILE: PERIPUMP.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2022-10-13
// PURPOSE: Arduino library for peristaltic pump


#include "PERIPUMP.h"


// CONSTRUCTOR
PERIPUMP::PERIPUMP(uint8_t pumpPin)
{
_pin = pumpPin;
_percentage = 0;
_sumTime = 0;
}


void PERIPUMP::begin()
{
_myServo.attach(_pin);
stop();
resetRunTime();
}


void PERIPUMP::stop()
{
_myServo.writeMicroseconds(1500);
if (_start != 0)
{
_sumTime += (millis() - _start);
_start = 0;
}
}


void PERIPUMP::setPercentage(float percentage)
{
// weighted runtime ?
// _sumTime += (millis() - _start) * abs(_percentage);
_percentage = constrain(percentage, -100, 100);

uint16_t ms = 0;
if (_percentage == 0)
{
ms = 1500;
if (_start != 0)
{
_sumTime += (millis() - _start);
_start = 0;
}
}
else if (_percentage > 0)
{
// 1600 - 2500
ms = 1600 + 9 * _percentage; // 9 == 900 / 100%
if (_start == 0) _start = millis();
}
else if (_percentage < 0)
{
// 500 - 1400
ms = 1400 + 9 * _percentage;
if (_start == 0) _start = millis();
}
_myServo.writeMicroseconds(ms);
}


float PERIPUMP::getPercentage()
{
return _percentage;
}


//////////////////////////////////////////////////////
//
// DURATION
//
float PERIPUMP::getRunTime()
{
float seconds = _sumTime;
if (_start != 0) seconds += (millis() - _start);
return seconds * 0.001;
}


float PERIPUMP::resetRunTime()
{
float s = getRunTime();
_sumTime = 0;
_start = 0;
return s;
}


// -- END OF FILE --

52 changes: 52 additions & 0 deletions PERIPUMP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once
//
// FILE: PERIPUMP.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2022-10-13
// PURPOSE: Arduino library for peristaltic pump
//
// Tested with dfrobot peristaltic pump DFR0523
//


#include "Arduino.h"
#include "Servo.h"

#define PERIPUMP_LIB_VERSION (F("0.1.0"))


class PERIPUMP
{
public:
PERIPUMP(uint8_t pumpPin);

void begin();

//////////////////////////////////////////////////////
//
// RUNNING
//
void stop();
void setPercentage(float percentage);
float getPercentage();

//////////////////////////////////////////////////////
//
// DURATION
//
float getRunTime(); // total seconds running since last reset / start.
float resetRunTime();


private:
uint8_t _pin;
float _percentage;
Servo _myServo;
uint32_t _sumTime = 0;
uint32_t _start = 0;
};


// -- END OF FILE --

Loading

0 comments on commit 76ab0f1

Please sign in to comment.