Created
August 20, 2015 06:30
-
-
Save analog-io/e661cd91c63561e89353 to your computer and use it in GitHub Desktop.
An Energia/Arduino sketch for adding BLE readout to an EEVBLOG uCurrent.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <analog_io.h> | |
#include <SPI.h> | |
analog_io radio(P3_5, P3_6, P2_5); | |
float ref, I; | |
float Current; | |
uint16_t batt,lp_ref; | |
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 }; | |
void setup() | |
{ | |
SPI.begin(); | |
SPI.setDataMode(SPI_MODE0); | |
SPI.setBitOrder(MSBFIRST); | |
radio.begin(); // Defaults 1Mbps, channel 0, max TX power | |
radio.setTXaddress((void*)txaddr); | |
analogReference(INTERNAL2V5); | |
} | |
void loop() | |
{ | |
lp_ref = analogRead(A0); | |
batt = analogRead(11)>>1; | |
if (lp_ref-batt>100) { | |
for (int k=1;k<=100;k++) { | |
ref -= ref/k; | |
ref += analogRead(A0)/k; | |
I -= I/k; | |
I += analogRead(A3)/k; | |
} | |
Current = (I-ref)*0.00244140625; | |
radio.print(Current,3); | |
radio.flush(); | |
delay(250); | |
radio.print(Current,3); | |
radio.flushBle(); | |
delay(250); | |
} | |
else { | |
sleep(5000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment