From 3e490df01fe5836bed6218bf67b7fe656ff36d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 6 Jun 2016 15:56:31 +0200 Subject: [PATCH] readme --- README.md | 4 ++-- main.c | 33 +++++++++++++++++---------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2659d5a..ba6b26f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,6 @@ to be something really strange on OSX). - RGB LED strip with WS2812 or WS2812B. It's set up for a 30-led strip, adjust as needed. +- Sonars: HC-SR04 (you can get them on eBay) - - +Wiring is configured in the C file at the top - adjust pin numbers however you like. diff --git a/main.c b/main.c index 30aef30..6ee97fd 100644 --- a/main.c +++ b/main.c @@ -1,18 +1,19 @@ -#include // register definitions -#include // storing data in program memory -#include // interrupt vectors -#include // delay functions +#include +#include +#include #include #include #include #include -// Include stuff from the library +// Custom library files #include "lib/iopins.h" #include "lib/usart.h" #include "lib/nsdelay.h" +// --- Pin assignments --- + #define WS_PIN 7 #define TRIG1_PIN 3 @@ -23,8 +24,14 @@ #define ECHO2_PIN 8 #define ECHO3_PIN 10 + +/** Number of LEDs in your strip */ #define LED_COUNT 30 + +/** averaging buffer length (number of samples) */ +#define MBUF_LEN 16 + /** Phase of the measurement (state-machine state) */ typedef enum { MEAS_WAIT_1, @@ -32,10 +39,6 @@ typedef enum { MEAS_DONE } MeasPhase; - -// averaging buffer length (number of samples) -#define MBUF_LEN 16 - /** Averaging buffer instance */ typedef struct { float data[MBUF_LEN]; @@ -234,18 +237,16 @@ int main(void) usart_puts_P(PSTR("\r\n")); usart_puts_P(PSTR("(c) Ondrej Hruska 2016\r\n")); usart_puts_P(PSTR("\r\n")); - usart_puts_P(PSTR("WS2812B LED strip - DIN: D7\r\n")); - usart_puts_P(PSTR("Sonars (HC-SR04) - trig/echo:\r\n")); - usart_puts_P(PSTR(" \"red\" D3/D2\r\n")); - usart_puts_P(PSTR(" \"green\" D9/D8\r\n")); - usart_puts_P(PSTR(" \"blue\" D11/D10\r\n")); - usart_puts_P(PSTR("\r\n")); usart_puts_P(PSTR("===========================\r\n")); int cnt = 0; while (1) { - sonar_measure(); + // This takes something close to 50 ms, varies with measured distances. + sonar_measure(); + + // Notice how the indicator blinking changes speed with distances + // You might want to do some adjustments here if you want 100% constant animation speed. if (++cnt == 20) { cnt = 0;