added new PCB + leds + prox
This commit is contained in:
2407
CAD/PCB/_autosave-clockclock.sch
Normal file
2407
CAD/PCB/_autosave-clockclock.sch
Normal file
File diff suppressed because it is too large
Load Diff
BIN
CAD/~$ESP32 Pins.xlsx
Normal file
BIN
CAD/~$ESP32 Pins.xlsx
Normal file
Binary file not shown.
6
clockclock/.vscode/settings.json
vendored
Normal file
6
clockclock/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"functional": "cpp",
|
||||
"tuple": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#ifndef HARDWAREVERSION
|
||||
#define HARDWAREVERSION 11
|
||||
#endif
|
||||
@@ -36,7 +38,7 @@
|
||||
#define MOT_DIR1 16
|
||||
#define MOT_RST1 18
|
||||
|
||||
#define MOT_VREF 25
|
||||
#define MOT_VREF A18 //25
|
||||
#define MOT_EN 13
|
||||
|
||||
#define ADDR0 33
|
||||
@@ -49,7 +51,7 @@
|
||||
|
||||
#define PROX_LED 27
|
||||
#define LED_DATA 26
|
||||
#define PROOX_IN 36
|
||||
#define PROX_IN 36
|
||||
|
||||
#define MCU_BUT_MIN 19
|
||||
#define MCU_BUT_PLUS 23
|
||||
@@ -57,3 +59,5 @@
|
||||
#warning NO BOARD SPECIFIED
|
||||
#endif
|
||||
|
||||
void initBoard( void );
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ framework = arduino
|
||||
lib_ldf_mode = deep+
|
||||
lib_deps =
|
||||
http://192.168.2.3/Bonobo.Git.Server/Accelstepper.git
|
||||
Fastled/FastLED @ ^3.4.0
|
||||
makuna/NeoPixelBus @ ^2.6.2
|
||||
|
||||
|
||||
; [env:clockclock_hwV10_L422]
|
||||
;platform = ststm32
|
||||
|
||||
12
clockclock/src/Proximity.h
Normal file
12
clockclock/src/Proximity.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "board.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#define PROXIMITYINTERVAL 100
|
||||
#define SAMPLERATE 10
|
||||
#define ANALOGSAMPLES 30
|
||||
|
||||
void initProximity( void );
|
||||
void handleProximity( void );
|
||||
void getProximity( void );
|
||||
6
clockclock/src/board.cpp
Normal file
6
clockclock/src/board.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "board.h"
|
||||
|
||||
void initBoard( void )
|
||||
{
|
||||
Serial.begin(115200);
|
||||
}
|
||||
@@ -25,3 +25,5 @@ void initButtons(void)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
uint8_t getAddress(void)
|
||||
{
|
||||
uint8_t address = 0;
|
||||
uint8_t address = COMMSBASE;
|
||||
|
||||
address += (digitalRead(ADDR0)) ? 1 : 0;
|
||||
address += (digitalRead(ADDR1)) ? 2 : 0;
|
||||
address += (digitalRead(ADDR2)) ? 4 : 0;
|
||||
address += (digitalRead(ADDR3)) ? 8 : 0;
|
||||
address += (!digitalRead(ADDR0)) ? 1 : 0;
|
||||
address += (!digitalRead(ADDR1)) ? 2 : 0;
|
||||
address += (!digitalRead(ADDR2)) ? 4 : 0;
|
||||
address += (!digitalRead(ADDR3)) ? 8 : 0;
|
||||
|
||||
return address;
|
||||
}
|
||||
@@ -27,23 +27,25 @@ void requestI2CEvent() {
|
||||
|
||||
uint8_t address;
|
||||
|
||||
void initI2C( void)
|
||||
void initComms( void)
|
||||
{
|
||||
Serial.print("init Comms");
|
||||
pinMode(ADDR0, INPUT_PULLUP);
|
||||
pinMode(ADDR1, INPUT_PULLUP);
|
||||
pinMode(ADDR2, INPUT_PULLUP);
|
||||
pinMode(ADDR3, INPUT_PULLUP);
|
||||
|
||||
delay(10);
|
||||
address = getAddress();
|
||||
|
||||
Serial.printf("selected address: %u", address);
|
||||
// Start the I2C Bus as Slave on address 9
|
||||
Wire.begin(address);
|
||||
// Attach a function to trigger when something is received.
|
||||
Wire.onReceive(receiveI2CEvent);
|
||||
Wire.onRequest(requestI2CEvent);
|
||||
//Wire.onReceive(receiveI2CEvent);
|
||||
//Wire.onRequest(requestI2CEvent);
|
||||
Serial.println(" :Ok");
|
||||
}
|
||||
|
||||
void handleI2C ( void )
|
||||
void handleComms ( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
#define MSGLEN 10
|
||||
#define COMMSBASE 80
|
||||
|
||||
class c_message
|
||||
{
|
||||
@@ -24,5 +25,5 @@ public:
|
||||
|
||||
};
|
||||
|
||||
void initI2C( void);
|
||||
void handleI2C ( void );
|
||||
void initComms( void);
|
||||
void handleComms ( void );
|
||||
|
||||
44
clockclock/src/led.cpp
Normal file
44
clockclock/src/led.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "led.h"
|
||||
|
||||
//CRGB leds[NUM_LEDS];
|
||||
|
||||
|
||||
uint64_t ledtimer1 = 0;
|
||||
uint8_t hue = 0;
|
||||
bool ledstate = 0;
|
||||
#define colorSaturation 128
|
||||
|
||||
NeoPixelBus<DotStarBgrFeature, DotStarMethod> LEDS(NUM_LEDS, LED_DATA);
|
||||
|
||||
RgbColor red(colorSaturation, 0, 0);
|
||||
RgbColor green(0, colorSaturation, 0);
|
||||
RgbColor blue(0, 0, colorSaturation);
|
||||
RgbColor white(colorSaturation);
|
||||
RgbColor black(0);
|
||||
|
||||
|
||||
|
||||
/* ---------------- */
|
||||
/* public functions */
|
||||
/* ---------------- */
|
||||
|
||||
void initLeds(void)
|
||||
{
|
||||
Serial.print("Init Leds: ");
|
||||
LEDS.begin();
|
||||
LEDS.ClearTo(black);
|
||||
|
||||
Serial.println("OK");
|
||||
}
|
||||
|
||||
void handleLeds(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if (currentmillis - ledtimer1 > LEDINTERVAL)
|
||||
{
|
||||
|
||||
|
||||
ledtimer1 = currentmillis;
|
||||
|
||||
}
|
||||
}
|
||||
11
clockclock/src/led.h
Normal file
11
clockclock/src/led.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "board.h"
|
||||
#include <FastLED.h>
|
||||
#include <NeoPixelBus.h>
|
||||
|
||||
#define NUM_LEDS 4
|
||||
#define LEDINTERVAL 10
|
||||
|
||||
void initLeds(void);
|
||||
void handleLeds(void);
|
||||
@@ -3,12 +3,20 @@
|
||||
#include "motor.h"
|
||||
#include "buttons.h"
|
||||
#include "movement.h"
|
||||
#include "Proximity.h"
|
||||
#include "led.h"
|
||||
#include "comms.h"
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
initBoard();
|
||||
initMotors();
|
||||
initButtons();
|
||||
initMovement();
|
||||
initProximity();
|
||||
initLeds();
|
||||
initComms();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -16,4 +24,7 @@ void loop() {
|
||||
handleMotors();
|
||||
handleButtons();
|
||||
handleMovement();
|
||||
handleProximity();
|
||||
handleLeds();
|
||||
handleComms();
|
||||
}
|
||||
@@ -11,6 +11,7 @@ MultiStepper motors;
|
||||
|
||||
void c_motor::init(bool setvref)
|
||||
{
|
||||
Serial.print("init Motors: ");
|
||||
pinMode(_rst, OUTPUT);
|
||||
pinMode(_en, OUTPUT);
|
||||
pinMode(_sclk, OUTPUT);
|
||||
@@ -27,9 +28,13 @@ void c_motor::init(bool setvref)
|
||||
|
||||
if (setvref)
|
||||
{
|
||||
pinMode(MOT_VREF, OUTPUT);
|
||||
Serial.print("Setup Vref: ");
|
||||
ledcSetup(0,12800,8);
|
||||
//pinMode(MOT_VREF, OUTPUT);
|
||||
ledcAttachPin(MOT_VREF,0);
|
||||
ledcWrite(MOT_VREF, 32);
|
||||
}
|
||||
Serial.println("OK");
|
||||
}
|
||||
|
||||
void c_motor::begin(void)
|
||||
|
||||
70
clockclock/src/proximity.cpp
Normal file
70
clockclock/src/proximity.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "Proximity.h"
|
||||
|
||||
uint64_t proximityTimer = 0;
|
||||
uint64_t sampleTimer = 0;
|
||||
uint16_t readbuffer[ANALOGSAMPLES];
|
||||
uint16_t readbuffer_idx = 0;
|
||||
bool firstOutputSampleReady = false;
|
||||
uint16_t currentProx = 0;
|
||||
|
||||
uint32_t addSample(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if (currentmillis - sampleTimer > SAMPLERATE)
|
||||
{
|
||||
sampleTimer = currentmillis;
|
||||
if (readbuffer_idx > ANALOGSAMPLES - 1)
|
||||
{
|
||||
readbuffer_idx = 0;
|
||||
firstOutputSampleReady = true;
|
||||
}
|
||||
digitalWrite(PROX_LED, HIGH);
|
||||
delay(3);
|
||||
readbuffer[readbuffer_idx++] = analogRead(PROX_IN);
|
||||
|
||||
digitalWrite(PROX_LED, LOW);
|
||||
|
||||
if (firstOutputSampleReady)
|
||||
{
|
||||
//average samples
|
||||
uint64_t sampleAvg = 0;
|
||||
for (int i = 0; i < ANALOGSAMPLES; i++)
|
||||
{
|
||||
sampleAvg += readbuffer[i];
|
||||
}
|
||||
//Serial.printf("AnalogRead_sum(%l)\n", sampleAvg);
|
||||
sampleAvg /= ANALOGSAMPLES;
|
||||
currentProx = sampleAvg;
|
||||
return sampleAvg;
|
||||
}
|
||||
}
|
||||
return readbuffer[readbuffer_idx - 1];
|
||||
}
|
||||
|
||||
void initProximity(void)
|
||||
{
|
||||
Serial.print("Proximity init:");
|
||||
pinMode(PROX_LED, OUTPUT);
|
||||
pinMode(PROX_IN, ANALOG);
|
||||
|
||||
for (auto sample : readbuffer)
|
||||
{
|
||||
sample = 0;
|
||||
}
|
||||
Serial.println(" OK ");
|
||||
}
|
||||
|
||||
void handleProximity(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if (currentmillis - proximityTimer > PROXIMITYINTERVAL)
|
||||
{
|
||||
//Serial.printf("proximity raw read = %u\n", currentProx);
|
||||
proximityTimer = currentmillis;
|
||||
}
|
||||
|
||||
addSample();
|
||||
}
|
||||
void getProximity(void)
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user