mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.4 AsyncAnalog
This commit is contained in:
parent
89504e50a4
commit
9ec1d36573
@ -2,5 +2,10 @@ compile:
|
|||||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||||
platforms:
|
platforms:
|
||||||
- uno
|
- uno
|
||||||
|
# - due
|
||||||
|
# - zero
|
||||||
- leonardo
|
- leonardo
|
||||||
|
# - m4
|
||||||
|
# - esp32
|
||||||
|
# - esp8266
|
||||||
|
- mega2560
|
@ -4,10 +4,14 @@ name: Arduino CI
|
|||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
arduino_ci:
|
runTest:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: Arduino-CI/action@master
|
- uses: ruby/setup-ruby@v1
|
||||||
# Arduino-CI/action@v0.1.1
|
with:
|
||||||
|
ruby-version: 2.6
|
||||||
|
- run: |
|
||||||
|
gem install arduino_ci
|
||||||
|
arduino_ci.rb
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// 0.1.1 2020-03-26 minor refactor
|
// 0.1.1 2020-03-26 minor refactor
|
||||||
// 0.1.2 2020-05-27 update library.json
|
// 0.1.2 2020-05-27 update library.json
|
||||||
// 0.1.3 2020-12-12 added Arduino CI, minor fixes
|
// 0.1.3 2020-12-12 added Arduino CI, minor fixes
|
||||||
|
// 0.1.4 2020-12-12 update Arduino CI, minor fixes
|
||||||
|
|
||||||
|
|
||||||
#include "AsyncAnalog.h"
|
#include "AsyncAnalog.h"
|
||||||
@ -29,6 +30,7 @@ AsyncAnalog::AsyncAnalog(const uint8_t pin)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncAnalog::start()
|
void AsyncAnalog::start()
|
||||||
{
|
{
|
||||||
#if defined(ADCSRB) && defined(MUX5)
|
#if defined(ADCSRB) && defined(MUX5)
|
||||||
@ -38,7 +40,7 @@ void AsyncAnalog::start()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ADMUX)
|
#if defined(ADMUX)
|
||||||
// set the analog reference (high two bits of ADMUX) and select the
|
// set the analogue reference (high two bits of ADMUX) and select the
|
||||||
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
|
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
|
||||||
// to 0 (the default).
|
// to 0 (the default).
|
||||||
ADMUX = (DEFAULT << 6) | (_pin & 0x07);
|
ADMUX = (DEFAULT << 6) | (_pin & 0x07);
|
||||||
@ -69,4 +71,5 @@ int AsyncAnalog::value()
|
|||||||
|
|
||||||
#endif // ARDUINO_ARCH_AVR
|
#endif // ARDUINO_ARCH_AVR
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
@ -2,12 +2,13 @@
|
|||||||
//
|
//
|
||||||
// FILE: AsyncAnalog.h
|
// FILE: AsyncAnalog.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.3
|
// VERSION: 0.1.4
|
||||||
// DATE: 2018-09-05
|
// DATE: 2018-09-05
|
||||||
// PURPOSE: async version of analogRead
|
// PURPOSE: async version of analogRead for AVR
|
||||||
// URL: https://github.com/RobTillaart/AsyncAnalog
|
// URL: https://github.com/RobTillaart/AsyncAnalog
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#if !defined(ARDUINO_ARCH_AVR)
|
#if !defined(ARDUINO_ARCH_AVR)
|
||||||
|
|
||||||
#error “AsyncAnalog library 0.1.3 only supports boards with an AVR processor .”
|
#error “AsyncAnalog library 0.1.3 only supports boards with an AVR processor .”
|
||||||
@ -21,12 +22,13 @@
|
|||||||
#include "wiring_private.h"
|
#include "wiring_private.h"
|
||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
#define ASYNCANALOG_LIB_VERSION "0.1.3"
|
#define ASYNCANALOG_LIB_VERSION (F("0.1.4"))
|
||||||
|
|
||||||
|
|
||||||
class AsyncAnalog
|
class AsyncAnalog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncAnalog(uint8_t pin);
|
AsyncAnalog(const uint8_t pin);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
bool ready();
|
bool ready();
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
|
|
||||||
[![Arduino CI](https://github.com/RobTillaart/AsyncAnalog/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
[![Arduino CI](https://github.com/RobTillaart/AsyncAnalog/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||||
|
[![Arduino-lint](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/arduino-lint.yml)
|
||||||
|
[![JSON check](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/jsoncheck.yml)
|
||||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AsyncAnalog/blob/master/LICENSE)
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AsyncAnalog/blob/master/LICENSE)
|
||||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AsyncAnalog.svg?maxAge=3600)](https://github.com/RobTillaart/AsyncAnalog/releases)
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AsyncAnalog.svg?maxAge=3600)](https://github.com/RobTillaart/AsyncAnalog/releases)
|
||||||
|
|
||||||
|
|
||||||
# AsyncAnalog
|
# AsyncAnalog
|
||||||
|
|
||||||
Arduino Library for async reading of an analog pin. **\[AVR ONLY\]**
|
Arduino Library for async reading of an analogue pin. **\[AVR ONLY\]**
|
||||||
|
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
AsyncAnalog is a library to read the analog port in an asynchronous way.
|
|
||||||
|
AsyncAnalog is a library to read the analogue port of an AVR in an asynchronous way.
|
||||||
This means that the user must explicitly **start** the ADC, check if it is **ready**
|
This means that the user must explicitly **start** the ADC, check if it is **ready**
|
||||||
and read out its **value**.
|
and read out its **value**.
|
||||||
|
|
||||||
@ -18,25 +22,30 @@ By using this class, the user prevents the (~112 uSec) blocking of the
|
|||||||
|
|
||||||
The library works only for AVR boards now, other platforms might be supported in the future.
|
The library works only for AVR boards now, other platforms might be supported in the future.
|
||||||
|
|
||||||
As the UNO has only one ADC that is multiplexed, one can only read one analog pin
|
As the UNO has only one ADC that is multiplexed, one can only read one analogue pin
|
||||||
in async way simultaneously.
|
in async way simultaneously.
|
||||||
|
|
||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
- **AsyncAnalog(uint8_t pin)** constructor, defines the analog pin to use.
|
- **AsyncAnalog(uint8_t pin)** constructor, defines the analogue pin to use.
|
||||||
|
|
||||||
The library consists of three main function:
|
|
||||||
|
|
||||||
- **void start()** triggers a new ADC reading.
|
- **void start()** triggers a new ADC reading.
|
||||||
- **bool ready()** returns true if sample is complete
|
- **bool ready()** returns true if sample is complete
|
||||||
- **int value()** returns the value
|
- **int value()** returns the value
|
||||||
|
|
||||||
|
|
||||||
## Operation
|
## Operation
|
||||||
|
|
||||||
The example **asyncAnalogTest2.ino** shows a loop of 1000 analogReads and prints
|
The example **asyncAnalogTest2.ino** shows a loop of 1000 analogReads and prints
|
||||||
over Serial at 115200 baud. The async test does this in less time. Note that faster
|
over Serial at 115200 baud. The async test does this in less time. Note that faster
|
||||||
baudrates shows an even bigger difference.
|
baud rates shows an even bigger difference.
|
||||||
|
|
||||||
During the printing, the sampling continues.
|
During the printing, the sampling continues.
|
||||||
|
|
||||||
|
|
||||||
|
## Future
|
||||||
|
|
||||||
|
- investigate other platforms
|
||||||
|
- fall back to normal analogRead for non AVR platforms ?
|
||||||
|
-
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
// VERSION: 0.1.1
|
// VERSION: 0.1.1
|
||||||
// DATE: 2018-09-05
|
// DATE: 2018-09-05
|
||||||
|
|
||||||
|
|
||||||
#include "AsyncAnalog.h"
|
#include "AsyncAnalog.h"
|
||||||
|
|
||||||
|
|
||||||
AsyncAnalog AA(A0);
|
AsyncAnalog AA(A0);
|
||||||
|
|
||||||
uint32_t start = 0;
|
uint32_t start = 0;
|
||||||
@ -22,6 +24,7 @@ void setup()
|
|||||||
start = micros();
|
start = micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -48,4 +51,5 @@ void loop()
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// END OF FILE
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.0
|
||||||
// DATE: 2020-03-27
|
// DATE: 2020-03-27
|
||||||
|
|
||||||
|
|
||||||
#include "AsyncAnalog.h"
|
#include "AsyncAnalog.h"
|
||||||
|
|
||||||
|
|
||||||
AsyncAnalog AA(A0);
|
AsyncAnalog AA(A0);
|
||||||
|
|
||||||
uint32_t start = 0;
|
uint32_t start = 0;
|
||||||
@ -70,4 +72,5 @@ void async_test()
|
|||||||
Serial.print("\n\n");
|
Serial.print("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// END OF FILE
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Syntax Coloring Map For AsyncAnalog
|
# Syntax Colouring Map For AsyncAnalog
|
||||||
|
|
||||||
# Datatypes (KEYWORD1)
|
# Data types (KEYWORD1)
|
||||||
AsyncAnalog KEYWORD1
|
AsyncAnalog KEYWORD1
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/AsyncAnalog.git"
|
"url": "https://github.com/RobTillaart/AsyncAnalog.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*"
|
"platforms": "*"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=AsyncAnalog
|
name=AsyncAnalog
|
||||||
version=0.1.3
|
version=0.1.4
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino Library for async reading of an analog pin
|
sentence=Arduino Library for async reading of an analog pin
|
||||||
|
@ -19,24 +19,30 @@
|
|||||||
// assertFalse(actual)
|
// assertFalse(actual)
|
||||||
// assertNull(actual)
|
// assertNull(actual)
|
||||||
|
|
||||||
|
|
||||||
#include <ArduinoUnitTests.h>
|
#include <ArduinoUnitTests.h>
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "AsyncAnalog.h"
|
#include "AsyncAnalog.h"
|
||||||
|
|
||||||
|
|
||||||
unittest_setup()
|
unittest_setup()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unittest_teardown()
|
unittest_teardown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unittest(test_none)
|
unittest(test_none)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "ASYNCANALOG_LIB_VERSION: %s\n", (char *) ASYNCANALOG_LIB_VERSION);
|
||||||
fprintf(stderr, "no unit test defined as library is HW specific");
|
fprintf(stderr, "no unit test defined as library is HW specific");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unittest_main()
|
unittest_main()
|
||||||
|
|
||||||
// --------
|
// --------
|
||||||
|
Loading…
Reference in New Issue
Block a user