This project has many parts to it, We try to publish them so you are able to replicate only that part, Or put them all together as we release them. This is Part 5 of the MEGA BREAD Series. Added 4-18-2017

This portion of the MEGA BREAD series focuses on reading values from the thumb stick, running a short math routine to adjust values, then use these values to set flash timings on two LED's.

 Find the YouTube Video Here

Assembly List

LabelPart TypeProperties
Part1 Arduino Mega ADK (Rev3) type Arduino MEGA ADK (Rev3)
Pin 10 Led LEDs package led10mm; variant 10mm
Pin 10 R 220Ω Resistor resistance 220Ω; package 2512 [SMD]; tolerance ±5%
Pin 11 Led LEDs package led10mm; variant 10mm
Pin 11 R 220Ω Resistor resistance 220Ω; package 2512 [SMD]; tolerance ±5%
Pin 12 Led Green (570nm) LED leg yes; package 3 mm [THT]; color Green (570nm)
Pin 12 R 220Ω Resistor resistance 220Ω; package 2512 [SMD]; tolerance ±5%
Pin 13 Led Red (633nm) LED leg yes; package 3 mm [THT]; color Red (633nm)
Pin 13 R 220Ω Resistor resistance 220Ω; package 2512 [SMD]; tolerance ±5%
Thumb Stick 1 Thumb Joystick  
VCC1 Battery block 9V voltage 9V

 

Exported with Fritzing 0.9.3- http://fritzing.org

 

Main objectives are below:

  1. Set the MAX flash timings so they can be seen.
  2. Read values from the thumb stick
  3. Ability to adjust the math when changing timings

The Values are simple enough:

int ledPinA = 11;
int ledPinB = 10;
int joyPin1 = A9; // slider variable connecetd to analog pin 0
int joyPin2 = A10; // slider variable connecetd to analog pin 1
int value1 = 0; // variable to read the value from the analog pin 0
int value2 = 0; // variable to read the value from the analog pin 1

 

The Code will also output to the Serial Monitor. Although this part is sketchy to me. it seems to play a huge role in the ability of the thumb stick to register with the Arduino.  This part will definetly change, very soon.

void setup() {
pinMode(ledPinA, OUTPUT); // initializes digital pins 0 to 7 as outputs
pinMode(ledPinB, OUTPUT);
Serial.begin(9600);
}

int treatValue(int data) {
return (data * 9 / 1024)+48;
}

 

The loop reads values using the "data" variable

produced when reading the thumb stick input.


void loop() {
// reads the value of the variable resistor
value1 = analogRead(joyPin1);
// this small pause is needed between reading
// analog pins, otherwise we get the same value twice
delay(100);
// reads the value of the variable resistor
value2 = analogRead(joyPin2);
digitalWrite(ledPinA, HIGH);
delay(value1);
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, HIGH);
delay(value2);
digitalWrite(ledPinB, LOW);
Serial.print('J');
Serial.print(treatValue(value1));
Serial.println(treatValue(value2));
}