Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Simple emoticon display. on: October 23, 2012, 02:17:40 am
Eh, Don't worry about jumping in too deep. I started using the Arduino to build a self contained 4 axis camera control rig. I still don't know anywhere near enough to do that but I am learning. If you are not on a major time limit, just go out and pick up an Arduino Uno and a starter kit and just start small, blink led, blink with delay, push on push off led ect... Then slowly start expanding what you can do.

I've been with it for a few weeks and although most of my 'projects' are trivial, I'm learning a lot more about the language, hardware and how to reach my goal.
If budget is an issue there are some great Arduino clones and just order mass part kits from overseas, very cheap.

If time is the issue I'd just pick up an Uno and buy the 14x9 LED shield as suggested above, start watching I2C tutorials and matrix display tutorials, get it to do some basic stuff and come back to this fine community for further assistance.

Be warned though, once you start understanding the Arduino, you'll be hooked, soon everything is an Arduino project.  smiley

I wish you the best of luck, although my knowledge is limited I'd be happy to help any way I can once you are on your way.
2  Using Arduino / Interfacing w/ Software on the Computer / Re: Arduino to Processing RGB Screen Communication (WORKING) on: October 22, 2012, 02:13:17 am
Thank you PaulS for the advice. I finally kept searching and turns out the answers were in the Tutorial section of the main Arudino.cc site the whole time. *Face Palm* Doh!

Any way I wanted to share the working sketches and the Arduino layout in case anyone else wanted to give it a shot. As always, advice is welcome and if you do this please share your experience.  smiley

Arduino Layout:



Arduino Code:
Code:
/*

 This is the Arduino half of the code to enable you to controll an RGB color swatch on your PC using an Arduino and three potentiometers
 
 This code was adapted from a tutorial called   Serial Call and Response in ASCII and can be found at http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII
 
 The original code and this adaptation are both in the public domain.
 
 A personal thank you to all the authors of this tutorial!
 */

int RedVal = 0;   
int GreenVal = 0;   
int BlueVal = 0;   
int inByte = 0;         // incoming serial byte
int RedPotPin= A0;
int GreenPotPin=A1;
int BluePotPin= A2;

void setup()
{
  // start serial port at 9600 bps and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  pinMode(RedPotPin, INPUT);   
  pinMode(GreenPotPin, INPUT); 
  pinMode(BluePotPin, INPUT); 
  establishContact();  // send a byte to establish contact until receiver responds
}

void loop()
{
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();
    // I had to map my potentiometers values as they did not all have the same resistance.
    RedVal = map(analogRead(RedPotPin), 0, 1023, 0, 255);

    GreenVal = map(analogRead(GreenPotPin), 33, 972, 0, 255);

    BlueVal = map(analogRead(BluePotPin), 0, 1023, 0, 255);
    // send sensor values:
    Serial.print(RedVal);
    Serial.print(",");
    Serial.print(GreenVal);
    Serial.print(",");
    Serial.println(BlueVal);               
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.println("0,0,0");   // send an initial string
    delay(300);
  }
}


Processing Code:
Code:
/*
This is the Processing half of the code to enable you to controll an RGB color swatch on your PC using an Arduino and three potentiometers

This code was adapted from a tutorial called   Serial Call and Response in ASCII and can be found at http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII

The original code and this adaptation are both in the public domain.

A personal thank you to all the authors of this tutorial!
*/


import processing.serial.*;     // import the Processing serial library
Serial myPort;                  // The serial port
float BrightnessRed;
float BrightnessGreen;
float BrightnessBlue;


void setup() {
  size(640,480);
  myPort = new Serial(this, "COM3" , 9600);

  // read bytes into a buffer until you get a linefeed (ASCII 10):
  myPort.bufferUntil('\n');

}

void draw() {
  background(BrightnessRed,BrightnessGreen,BrightnessBlue);
}

// serialEvent  method is run automatically by the Processing applet
// whenever the buffer reaches the  byte value set in the bufferUntil()
// method in the setup():

void serialEvent(Serial myPort) {
  // read the serial buffer:
  String myString = myPort.readStringUntil('\n');
  // if you got any bytes other than the linefeed:
    myString = trim(myString);
   
    // split the string at the commas
    // and convert the sections into integers:
    int sensors[] = int(split(myString, ','));
    // print out the values you got:
    for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
    }
    // add a linefeed after all the sensor values are printed:
        println();
    if (sensors.length > 1) {
      BrightnessRed =sensors[0];
      BrightnessGreen = sensors [1];
      BrightnessBlue= sensors [2];
    }
    // send a byte to ask for more data:
    myPort.write("A");
  }
3  Using Arduino / Interfacing w/ Software on the Computer / Arduino to Processing RGB Screen Communication on: October 16, 2012, 03:52:27 am
 Hello everyone, I've only been working with the Arduino for about a week and Processing much less then that. I'm working very hard to teach myself how it all works for a big project I want to do in the future, but I really want to understand it, not just follow tutorials and be satisfied.

Recently I followed a tutorial by Jeremy Blum about controlling the a single color of your screen using a pot and Processing.



 I followed it and got it working well, but then I wanted to push it to control RGB color using three pots. I made the Arduino code and got it outputting serial communication stating each RGB value separated by a char.

ie.. R255G255B0

I'm not sure if I'm going about this in the right way or not but I'm completely stuck on the Processing side. There are a few texts out there about it but they are as clear as mud to me. I just included the base code without trying to read each value, all attempts were major failures.  smiley-fat Any help would be greatly appreciated. Thank you very much.

Arduino Code:

Code:
int RedPotPin = 0;
int GreenPotPin= 1;
int BluePotPin= 2;

void setup()
{
  pinMode(RedPotPin, INPUT);
  pinMode(GreenPotPin, INPUT);
  pinMode(BluePotPin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  int RedVal = map(analogRead(RedPotPin), 0, 1023, 0, 255);
  int GreenVal = map(analogRead(GreenPotPin), 33, 972, 0, 255);
  int BlueVal = map(analogRead(BluePotPin), 0, 1023, 0, 255);
  Serial.print('R');
  Serial.print(RedVal);
  Serial.print("G");
  Serial.print(GreenVal);
  Serial.print("B");
  Serial.print(BlueVal);
  Serial.println();
  delay(100);
}


Processing Code:

Code:
import processing.serial.*;
Serial port;
float brightnessRed = 0;
float brightnessGreen = 0;
float brightnessBlue = 0;

void setup()
{
  size (500,500);
  port = new Serial(this, "COM3", 9600);
  port.bufferUntil('\n');
 
}

void draw()
{
  background(brightnessRed,brightnessGreen,brightnessBlue);
}

void serialEvent (Serial port)
{
 brightnessRed = float(port.readStringUntil('G'));
}


P.S. I know this has no real world application, I'm just trying it to learn.
4  Using Arduino / LEDs and Multiplexing / Re: Multiple buttons with single wire input, help needed. on: October 15, 2012, 02:14:24 am
Well I'm back to bother you guys some more.

 I manged to get all four switches controlling their own LED, push on, push off, held buttons ignored. So I'm excited about that. However I still have the obvious issue of the switches bouncing. I've debounced single switches using delay() but I've been told this is bad practice. On top of that I don't really see that being feasible with this switch array. Also with it all being through one analog pin I don't see a hardware solution. I know to you guys this is probably a simple problem but I feel that if I don't really learn and understand these basics I'm just shooting myself in the foot before I learn to walk. 

Here is my current code, any comments are always welcome, and of course examples. Thanks so much!

Code:


// Define Constants
const int switcharrayPin=A0; // Set switch array pin to analog pin 0
const int ledonePin=11; // Set LED pin to 11
const int ledtwoPin=10; // Set LED two pin to 10
const int ledthreePin=9;// Set LED three to pin 9
const int ledfourPin=6; // Set LED four to pin 6



// Define Variables
long int switcharrayvalue=0; // Keep track of the switch value between 0 and 1280

boolean switchonecurrent=0; // Boolean to hold current switch one position
boolean switchonelast=0; // Boolean to hold last switch one position

boolean switchtwocurrent=0; //Hold switch twos position
boolean switchtwolast=0; //Track switch twos position

boolean switchthreecurrent=0; //hold switch threes position
boolean switchthreelast=0; //track switch threes position

boolean switchfourcurrent=0; //hold switch fours position
boolean switchfourlast=0; //track switch threes position




void setup()
{
  pinMode (switcharrayPin, INPUT); //set switch array pin to an input
  pinMode (ledonePin, OUTPUT); // set LED one pin to output
  pinMode (ledtwoPin, OUTPUT); // set LED two pin to output
  pinMode (ledthreePin, OUTPUT); //set LED three pin to output
  pinMode (ledfourPin, OUTPUT); //set LED four pin to output
}




void loop()
{

  // LED ONE CHECK AND SWITCH CODE
  switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array
  if(switcharrayvalue > 350 && switcharrayvalue < 550 && switchonelast==false)// See if switch one is pressed when it was not pressed before
  {
    switchonecurrent = !switchonecurrent; // If so, flip switch ones value
    switchonelast=true; // If so, make switch ones last state to true
  }
  else
  {
    if(switcharrayvalue < 350 || switcharrayvalue > 550)// See if button one is not pressed
    {
      switchonelast=false; // If it's not, set switch ones last state to false
    }
  }
  digitalWrite(ledonePin,switchonecurrent); // Write switch ones current state to LED One






    //  LED TWO CHECK AND SWITCH CODE
  switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array
  if(switcharrayvalue > 320 && switcharrayvalue < 350 && switchtwolast==false)// See if switch two is pressed when it was not pressed before
  {
    switchtwocurrent = !switchtwocurrent; // If so, flip switch twos value
    switchtwolast=true; // If so, make switch twos last state to true
  }
  else
  {
    if(switcharrayvalue < 320 || switcharrayvalue > 350)// See if button two is not pressed
    {
      switchtwolast=false; // If it's not, set switch twos last state to false
    }
  }

  digitalWrite(ledtwoPin,switchtwocurrent); // Write switch twos current state to LED two





  //  LED THREE SWITCH AND CODE
  switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array
  if(switcharrayvalue > 240 && switcharrayvalue < 260 && switchthreelast==false)// See if switch three is pressed when it was not pressed before
  {
    switchthreecurrent = !switchthreecurrent; // If so, flip switch threes value
    switchthreelast=true; // If so, make switch threes last state to true
  }
  else
  {
    if(switcharrayvalue < 240 || switcharrayvalue > 260)// See if button three is not pressed
    {
      switchthreelast=false; // If it's not, set switch threes last state to false
    }
  }

  digitalWrite(ledthreePin,switchthreecurrent); // Write switch threes current state to LED three




  //  LED FOUR CHECK AND SWITCH CODE
  switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array
  if(switcharrayvalue > 190 && switcharrayvalue < 220 && switchfourlast==false)// See if switch four is pressed when it was not pressed before
  {
    switchfourcurrent = !switchfourcurrent; // If so, flip switch fours value
    switchfourlast=true; // If so, make switch fours last state to true
  }
  else
  {
    if(switcharrayvalue < 190 || switcharrayvalue > 220)// See if button four is not pressed
    {
      switchfourlast=false; // If it's not, set switch fours last state to false
    }
  }

  digitalWrite(ledfourPin,switchfourcurrent); // Write switch fours current state to LED four

}



5  Using Arduino / LEDs and Multiplexing / Re: Multiple buttons with single wire input, help needed. on: October 14, 2012, 08:20:08 am
Thanks for the reply!

I know the code I provided won't give the desired result, it was just more or less the foundation that I'm building off of.

I've been fighting with this all night and finally stripped it down to a single led, coded it as if it was a digital switch just provding high or low, and not an analog. Then I just went back and added my if() statements. Finally it works! Now I'd just need to add separate booleans for each of my four LEDS but I might actually be able to handle that.  smiley-razz

If anyone is interested here is the working code:


Code:

/*

 Desired Effects:
 Led One, When button one is pressed, LED one is On.
 Do not change state untill button is released and pressed again.
 
 */

// Define Constants
const int switcharrayPin=A0; // Set switch array pin to analog pin 0
const int ledonePin=11; // Set LED pin to 11

// Define Variables
boolean switchonecurrent=false; // Boolean to hold current switch position
boolean switchonelast=false; // Boolean to hold last switch position
long int switcharrayvalue=0; // Keep track of the switch value between 0 and 1280



void setup()
{
  pinMode (switcharrayPin, INPUT); //set switch array pin to an input
  pinMode (ledonePin, OUTPUT); // set switch array pin to an output
}




void loop()
{
  switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array
  if(switcharrayvalue > 350 && switcharrayvalue < 550 && switchonelast==false)// See if switch one is pressed when it was not pressed before
  {
    switchonecurrent = !switchonecurrent; // If so, flip switch ones value
    switchonelast=true; // If so, make switch ones last state to true
  }
  else
  {
    if(switcharrayvalue < 350 || switcharrayvalue > 550)// See if button one is not pressed
    {
      switchonelast=false; // If it's not, set switch ones last state to false
    }
  }

  digitalWrite(ledonePin,switchonecurrent); // Write switch ones current state to LED One
}


6  Using Arduino / LEDs and Multiplexing / Multiple buttons with single wire input, help needed. on: October 14, 2012, 02:31:42 am
Hello everyone, I'm new to the Arduino community and have only been learning for a couple of days. I have greatly enjoyed learning and have discovered a lot from looking at these forums. However I'm stumped on my latest endeavor.

I've managed to get each button to control a separate LED through a single analog wire. The problem is I can not figure out for the life of me how to not continue to repeat the effect. For instance, when I press button one, led one increases in brightness. If I hold down button one, led one continues to cycle through it's brightness level.

In short I just want a held button to act as a single button action and not continually repeat. One press, one action, until it is released and pressed again. I've tried several ways of doing this to no avail so I'll share my raw setup up and code. If you can help that would be great, and feel free to be honest if I've just done something completely backwards. I may be a noob but I can take some criticism. Thanks in advance.

And of course, if you want to use this code and/or setup feel free, just please share your uses/discoveries.  smiley

Here's the setup:



And here is my code:

Code:

/*

Desired effects:

LED ONE, when button is pressed increase one level in brightness untill button is released, and pressed again, then increase in brightness again
LED TWO, only light whil button two is pressed and held.
LED THREE and FOUR, Light when button is pressed. Turn off when button is pressed for a second time

*/



const int switcharrayPin=0; //switch array to analog pin 0
const int ledonePin=11; // LED ONE
const int ledtwoPin=10; // LED TWO
const int ledthreePin=9; // LED THREE
const int ledfourPin=6; // LED FOUR

int ledonelevel=0; // Set ledone begining level

boolean switchone = false; // Hold value of Switch ONE
boolean switchtwo= false; // Hold value of Switch TWO
boolean switchthree= false; // Hold value of Switch THREE
boolean switchfour = false; // Hold value of Switch FOUR



void setup()
{
  Serial.begin(9600); // Start serial communication
  pinMode (switcharrayPin, INPUT); // set switch array to input
  pinMode (ledonePin, OUTPUT); // set ledone to output
  pinMode (ledtwoPin, OUTPUT); // set ledtwo to output
  pinMode (ledthreePin, OUTPUT); // set ledthree to output
  pinMode (ledfourPin, OUTPUT); // set ledfour to output
}



void loop()
{
  int switcharrayval = analogRead(switcharrayPin); //Read switcharryPin

    if(switcharrayval > 350 && switcharrayval < 550) //Check if switch one was pressed
  {
    ledonelevel = ledonelevel + 51; // Add 51 to ledonelevel
    if (ledonelevel >255) ledonelevel=0; //Recycle LED after max level
    analogWrite(ledonePin, ledonelevel); // Cycle led through level
  }

  if(switcharrayval > 260 && switcharrayval < 350) // Check if switch two was pressed
  {
    switchtwo=true; // Turn on switch two
  }
  if (switcharrayval < 260 || switcharrayval > 350) // Check if switch two was released
  {
    switchtwo=false; // Turn off switch two
  }
  digitalWrite(ledtwoPin, switchtwo); // Set ledtwo to switch two


    if(switcharrayval > 230 && switcharrayval < 300) // Check if switch three is pressed
  {
    delay(10);
    switchthree=!switchthree; // If so reverse the value of switch three
    digitalWrite(ledthreePin, switchthree); // Set ledthree ledthree to same value as switch three
  }

  if(switcharrayval > 150 && switcharrayval < 225) // Check if switch four is pressed
  {
    switchfour=!switchfour; // If so reverse the value of switch four
    digitalWrite(ledfourPin, switchfour); // Set ledfour to same value as switch four
  }

  Serial.println(analogRead(switcharrayPin)); // Display switcharrayPin value in serial monitor
  delay(100); // Set serial monitor delay
}

Pages: [1]