Hi all,
I have a question that involves a lot of inputs and outputs on the Arduino. My question is how do I go about selecting the right information for feeding into a program and sending the right information to the right output on the Arduino? My project has:
10 Linear Pots
8 buttons,
a joy stick like device (basically 2 pots)
RGB LEDS,
Heres a block diagram:
How do i go about making the outputs usable to a program being written in Python and the inputs usable too? This is the code I have so far and due to a lack of funds I cannot test to see if it works in any sense!
#include <avr/pgmspace.h>
int up_button = 0;
int down_button = 0;
int currentColorValueRed;
int currentColorValueGreen;
int currentColorValueBlue;
// Init the Pins used for PWM
const int redPin = 5;
const int greenPin = 6;
const int bluePin = 7;
//Joystcik stuff
const int selectPin = 2;
const int joystick_xPin = A0;
const int joystick_yPin = A5;
int oldX = 0;
int oldY = 0;
int oldSelect = 0;
//Mux control pins
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
//Mux in "SIG" pin
int SIG_pin = 0;
void setup() {
Serial.begin(9600);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
//
digitalWrite(10, HIGH);
//RBG LED Pins
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
int joystick_x;
int joystick_y;
int select;
int fader0 = map(analogRead(0), 0, 1023, 0, 255);
int fader1 = map(analogRead(1), 0, 1023, 0, 255);
int fader2 = map(analogRead(2), 0, 1023, 0, 255);
int fader3 = map(analogRead(3), 0, 1023, 0, 255);
int fader4 = map(analogRead(4), 0, 1023, 0, 255);
int fader5 = map(analogRead(5), 0, 1023, 0, 255);
int fader6 = map(analogRead(6), 0, 1023, 0, 255);
int fader7 = map(analogRead(7), 0, 1023, 0, 255);
int fader8 = map(analogRead(8), 0, 1023, 0, 255);
int fader9 = map(analogRead(9), 0, 1023, 0, 255);
down_button = digitalRead(7); // read input value
if (down_button == LOW) { // check if the input is LOW (button pressed)
Serial.print(1);
} else {
Serial.print(0);
}
up_button = digitalRead(8); // read input value
if (up_button == LOW) { // check if the input is LOW (button pressed)
Serial.print(1);
} else {
Serial.print(0);
}
joystick_x = map(analogRead(joystick_xPin), 0, 1023, 1, 20);
joystick_y = map(analogRead(joystick_yPin), 0, 1023, 1, 20);
select = !digitalRead(selectPin);
if((oldX != joystick_x) || (oldY != joystick_y) || (oldSelect != select)){
Serial.print("joystick X: ");
Serial.print(joystick_x);
Serial.print(" joystick Y: ");
Serial.print(joystick_y);
if(select){
Serial.print("select");
}
Serial.println("");
oldX = joystick_x;
oldY = joystick_y;
oldSelect = select;
}
delay(10);
// Write the color to each pin using PWM and the value gathered above
analogWrite(redPin, currentColorValueRed);
analogWrite(bluePin, currentColorValueBlue);
analogWrite(greenPin, currentColorValueGreen);
//Loop through and read all 16 values
//Reports back Value at channel 6 is: 346
for(int i = 0; i < 16; i ++){
Serial.print("Fader");
Serial.print(i);
Serial.print(": ");
Serial.println(map(readMux(i), 0, 1023, 0, 255));
delay(1000);
}
}
int readMux(int channel){
int controlPin[] = {s0, s1, s2, s3};
int muxChannel[16][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
{1,1,0,0}, //channel 3
{0,0,1,0}, //channel 4
{1,0,1,0}, //channel 5
{0,1,1,0}, //channel 6
{1,1,1,0}, //channel 7
{0,0,0,1}, //channel 8
{1,0,0,1}, //channel 9
{0,1,0,1}, //channel 10
{1,1,0,1}, //channel 11
{0,0,1,1}, //channel 12
{1,0,1,1}, //channel 13
{0,1,1,1}, //channel 14
{1,1,1,1} //channel 15
};
//loop through the 4 sig
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[channel][i]);
}
//read the value at the SIG pin
int val = analogRead(SIG_pin);
//return the value
return val;
}
Parts of the code can only be finished when I get my Arduino. (When ever that will happen!)
Thanks in advanced,
Callum