Close

Week 4

A project log for Mood Watch

A watch that can be used to describe emotions and their intensity. Twist the dial to control the color of the LED light.

nehaNeha 05/02/2023 at 18:250 Comments

Week 3 summary: The Adafruit feather adalogger was set up and wired to the encoder and LED. This is what will be used to test the code and troubleshoot. The coding process was also started. Our code in short displays different RGB values when the encoder is turned. Each of the RGB (red, blue, green) values changes based on different positions of the encoder. We viewed those encoder readings this week and were pleased to see the LED change color, as that indicates that our code is working, though it may be just a few colors at the start.

Week 3's logs

We wired the encoder and LED to the Aurdino. We are using these parts to test and experiment with code while waiting for the actual materials to arrive. This encoder, LED, and Aurdino will help us complete and troubleshoot the code.

These are the encoder readings. The value changes by one every click when the dial is being rotated. These encoder readings also change the color gradually by increasing or decreasing each of the RGB color concentrations. This gradually changes the colors.

Our code for when we put the encoder position into the RGB value to change the color of the LED. This code affects the encoder position to manipulate the value of the concentration of each color in RGB, such as Red Green Blue. As the encoder position increases different variables of RBG are also manipulated. All of this affects the color of the LED.

Version 1 of code, still in progress.

#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    10

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 32

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products

//encoder
// Rotary Encoder Inputs
#define CLK 13
#define DT 12
#define SW 6

int counter = 0;
int updatedcounter = 0;
int currentStateCLK;
int lastStateCLK;
String currentDir ="";
unsigned long lastButtonPress = 0;


void setup() {
  strip.begin();
  strip.setBrightness(15);
  strip.show(); // Initialize all pixels to 'off'

// Set encoder pins as inputs
  pinMode(CLK,INPUT);
  pinMode(DT,INPUT);
  pinMode(SW, INPUT_PULLUP);

  // Setup Serial Monitor
  Serial.begin(9600);

  // Read the initial state of CLK
  lastStateCLK = digitalRead(CLK);

}
void loop()  {
      // Read the current state of CLK
  currentStateCLK = digitalRead(CLK);

  // If last and current state of CLK are different, then pulse occurred
  // React to only 1 state change to avoid double count
  if (currentStateCLK != lastStateCLK  && currentStateCLK == 1){

    // If the DT state is different than the CLK state then
    // the encoder is rotating CCW so decrement
    if (digitalRead(DT) != currentStateCLK) {
      counter --;
      currentDir ="CCW";
    } else {
      // Encoder is rotating CW so increment
      counter ++;
      currentDir ="CW";

            updatedcounter = counter * 4;
      strip.setPixelColor(3, rgbA, rgbB, rgbC);

      strip.show();

    }

    Serial.print("Direction: ");
    Serial.print(currentDir);
    Serial.print(" | Counter: ");
    Serial.println(counter);
  }

  // Remember last CLK state
  lastStateCLK = currentStateCLK;

  // Read the button state
  int btnState = digitalRead(SW);

  //If we detect LOW signal, button is pressed
  if (btnState == LOW) {
    //if 50ms have passed since last LOW pulse, it means that the
    //button has been pressed, released and pressed again
    if (millis() - lastButtonPress > 50) {
      Serial.println("Button pressed!");
    }

    // Remember last button press event
    lastButtonPress = millis();
  }

  // Put in a slight delay to help debounce the reading
  delay(1);

   

}

Discussions