tanya
Published © GPL3+

Spoon counter

A simple touch-to-move indicator light to show anything you like on a scale of 1-7, this one counts spoons left for tasks!

BeginnerProtip1 hour187

Things used in this project

Hardware components

Flowers Bluetooth brooches
Art by Physicist Flowers Bluetooth brooches
×1
Li-Ion Battery 100mAh
Li-Ion Battery 100mAh
×1
SparkFun Cerberus USB Cable - 6ft
SparkFun Cerberus USB Cable - 6ft
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

scissors, generic
marker pen, any colour

Story

Read more

Code

touch_to_move_pixel

Arduino
Hopefully the code is commented well enough. Touch the centre of the flower to move the indicator pixel.
// you need the Adafruit Neopixel library
// Made to run on the kitty yeung flower brooch
// code conceived and bodged together by Tanya Fish during hackster holiday hack

// I have no clue if it needs the avr bit or not so I left it in
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// the cap touch is on pin 6
#define TOUCHPIN   6

// the vibration motor is on pin 5 - later I may add a bit to use this too so have left it in
#define VMPIN      5     //Vibration motor pin

// sets the number of presses to zero at the start
int presses =0;
int prestate =0;

// the pixels are on pin 9
#define PIXELPIN        9 

// there are 7 pixels on the flower brooch
#define NUMPIXELS 7

// all the settings the neopixel library needs to hear
Adafruit_NeoPixel pixels(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800);


void setup() {

  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
   // initialize serial communication at 9600 bits per second:
  Serial.begin(115200);
  // make the touch pin an input
  pinMode(TOUCHPIN, INPUT);
  // initialize digital pin for the vibration motor as an output
  pinMode(VMPIN, OUTPUT);
 
}

void loop() {

  // read the input pin:
  int touchState = digitalRead(TOUCHPIN);
  // print out the state of the button:
  Serial.println(touchState);
  delay(10);        // delay in between reads for stability
  
  pixels.clear(); // Set all pixel colors to 'off'
  pixels.show();

// check if the flower centre is pressed. If it is, then the touchState is HIGH:
  if (touchState == HIGH && prestate == 0) {
    presses++;
    Serial.println(presses);
    
    prestate = 1;
  } else if(touchState == LOW) {
    prestate = 0;
  
  }
  
    // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
    // this is set to magenta because I like magenta - change it if you like
    for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
    pixels.setPixelColor(presses, pixels.Color(100, 0, 100));

    pixels.show();   // show the updated pixel position
   
  }

  // if the light has gone round the scale once, go back to the beginning
  if (presses == 8) {
    presses=0;
    Serial.println(presses);
    prestate = 1;
  }

}

Credits

tanya

tanya

2 projects • 10 followers
Permanently working on something - ex hardware, technical documentation, now academic. Read my tutorials on Make, Hackspace, pimoroni.com.

Comments