28 September 2019

Mapping: Poor Man's Nonfunctional Wired Air Pods

GOAL: Create an analog system for changing the color of a single RGB pixel.

OBJECTIVE: To practice mapping different ranges of values.

MATERIALS:

  • 20x Jumper Wires
  • 1x RGB LED
  • 3x 220ohm resistors
  • 1x Water Sensor
  • 1x Analog/Digital Joystick
  • 1x Pentiometer
  • 1x Passive Buzzer
  • 1x Elegoo UNO R3




Admittedly, I am less excited to type this up after my RGB LEDs burned my eyes out,
but let's get into it. ðŸŒˆðŸŒŸ

Mapping These Pods

So, thanks to a resurface of stale memes in my friend group, the really convoluted and obtuse narrative of my device intertwines with that of wired air pods-- or as we poor folk say, headphones. As such, I decided to include a joystick to simulate play controls, a pentiometer to simulate volume control, and a water sensor so as to protect one's bourgeoisie status. It's not remotely similar to an actual set of air pods, but it's what I kept in mind while designing this amalgamation.


Original Mockup
Uses colors to denote relationships and overall circuit flow

In my original plans, seen above, I decided to have different colors coordinated to different analog inputs. The water sensor uses red like an alarm. The joystick, outputting three values, is associated with two colors and the override mode. Lastly, the pentiometer, which controls volume, is paired with green so as not to be confused with other outputs.

Here's the result, though it's important to note some of the modules (joystick & water sensor) are off-screen due to wire limitations. I've also included the schematic, demonstration, and my code to better clarify the project's functionality. While I did have some further plans for the buzzer and joystick-- namely the joystick controlling pitch or acting like next/previous-- too many attempts at failed debugging have pushed those plans to a later, more zen-ful date.







I don't know if you can hear my
lack of caffeine, but I sure can.



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*************************************************
 * Pins
 *************************************************/

// Defining Pitches

// LED, PWM

const int blueDude = 3;
const int greenDude = 5;
const int redDude = 6;
int index = 0;
int alert = 10;
int fade = 10;

// Speaker, PWM

const int speakerBoy = 11;
int speakerToggle = 0;

// Joystick

const int rollingGirl = 12;
const int rollingX = A1;
const int rollingY = A0;
int buttonToggle = 0;

// Pentiometer

const int twirlyBoy = A3;

// Water Sensor

const int waterBoy = A5;

/*************************************************
 * Setup
 *************************************************/

void setup() {
  // Outputs
  pinMode(redDude, OUTPUT);
  pinMode(blueDude, OUTPUT);
  pinMode(greenDude, OUTPUT);
  pinMode(speakerBoy, OUTPUT);
  digitalWrite(speakerBoy, LOW);

  // Inputs
  pinMode(rollingGirl, INPUT);
  digitalWrite(rollingGirl, HIGH);
  
  Serial.begin(9600);
}

/*************************************************
 * Loop
 *************************************************/

void loop() {
  delay(50);  

  // GATHER INPUTS
  
  // Check Inputs and obtain values
  // joystick, pentiometer, water sensor
  // TwirlVolume: use pentiometer to set buzzer volume
  int buttonState = digitalRead(rollingGirl);
  int xState = analogRead(rollingX);
  int yState = analogRead(rollingY);
  int twirlyValue = analogRead(twirlyBoy);
  int twirlVolume = twirlyValue * (5.0/1023.0);
  int waterValue = analogRead(waterBoy);

  // MAP VALUES
  
  int rollingMapX = map(xState, 0, 1024, 0, 255);
  int rollingMapY = map(yState, 0, 1024, 0, 255);
  int twirlyMap = map(twirlyValue, 0, 1023, 0, 255);
  int waterMap = map(waterValue, 0, 1023, 0, 255);

  // TOGGLE
  // Button and toggle are controlled by joystick press
  // If button is pressed, handle toggle accordingly
  if (buttonState == 0) {
    if (buttonToggle == 0) {
      buttonToggle++;
    } else { 
      buttonToggle--; 
    }
  }

  // SEQUENCES
  // First: Check if toggle is set; if not, continue with sequences
  // Second: Check if rich airpods are wet, flash alarm so as not to become poor
  // General sequence: map red/blue to joystick, and green to pentiometer
  // Finally, if toggle was set, disable rest of sequences

  if (buttonToggle == 0){
    // Flash LED like alert if water sensor trips
    if (waterMap >= 20) {
      analogWrite(blueDude, LOW);
      analogWrite(greenDude, LOW);
      analogWrite(redDude, index);
      index = index + alert;
      if (index <= 0 || index >= 250) {
        alert = -alert;
      }
    // General map to joystick and pentiometer
    } else {
      analogWrite(blueDude, rollingMapX);
      analogWrite(redDude, rollingMapY);
      analogWrite(greenDude, twirlyMap);
      analogWrite(speakerBoy, twirlVolume);
    }
  // Override Sequence
  } else {
      for (int x = 255; x > 0; x--) {
        analogWrite(redDude, x * -1);
        analogWrite(blueDude, x * 5);
        analogWrite(greenDude, x * 2);
        delay(50);
      }
  }
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.