Git Product home page Git Product logo

iggy's Introduction

Arduino project template

This is a template for Arduino projects that integrate multiple sensors and LEDs. (Servo control functionality coming soon).

Usage

You'll need at a minimum to modify hw_layout.h:

  • Declare named constants for your pin numbers (to protect your mental health)
  • Declare led objects from your LEDs. This is as simple as led redLed = led(RED_LED_PIN, MAX_RED); or rgb_led xyz = { X_LED_PIN, Y_LED_PIN, Z_LED_PIN , 0, MAX_RGB};.
  • Declare your sensor functions; sometimes just int heat_sensor () { return analogRead(HEAT_SENSOR_PIN);}, but also allowing for combinations of sensor values and digital sensors read through serial communication.
  • Initialize value streams: stream heat = stream(&heat_sensor);. Streams have a short history enabling time differences and smoothing, as well as a calibration object.
  • Calibrate: t0 = millis(); heat.cal.begin(); while millis()<t0+time_you_want {heat.cal.step();} heat.cal.end(). (In this template we calibrate several sensors together in a calibrate_streams() utility.)

Your sketch file (ending in .ino) can then be quite simple:

#define SECONDS * 1000

#include "calstream.h"
#include "leds.h" 
#include "hw_layout.h" // maps hardware to sensors and leds and provides setup/update utilities

unsigned long t0 = 0; // restart with t0=millis() after each cycle
float R, G, B;

void setup() {
  redLed.write(255); // just for visual feedback
  pin_setup();
  calibrate_streams(10 SECONDS);
  redLed.write(0);
  t0 = millis();
  
void loop() {
  if (millis() - t0 > 120 SECONDS) {
    calibrate_streams(3 SECONDS);
    t0 = millis();
  }
  heat.update(); // but note the update_sensors() utility in hw_layout.h
  R = 255 * map(heat.zscore(), 
          -1.96,1.96,
          0,1) + map(side_heat.zscore(),-1.96,1.96,0,1);

  G = 255 * map(heat.bell_curve(),
          0, 1,
          0,1);

  B = 255 * map(heat.diff(),
          -20, 20,
          0, 1);
  xyz.write_rgb(R,G,B);
  delay(50);
}

Structure

Besides the sketch, there are three groups of files in this template:

  • hw_layout.h -- is a file you must customize to map your hardware to useful stream and led,rgb_led objects.
  • leds.h and leds.cpp -- paricularly useful for RGB leds, but can serve as starter code for your own ideas
  • calstream.h and calstream.cpp

License

This is a "learning in public" type of project, licensed by the SILLY PUBLIC LICENSE: silly usage is governed by an Apache 2.0 license, while serious usage is not authorized. It should, however, help the casual Arduino user to take the leap into cleaner code and functionality encapsulation.

iggy's People

Contributors

asemic-horizon avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.