Show Posts
Pages: [1] 2
1  Using Arduino / Installation & Troubleshooting / Errors with FTDI BASIC with pro mini 3.3v on: May 21, 2011, 01:26:16 am
I just get the same not in sync errors and protocol errors and spent a good 12 hours trying to figure this out but no luck, so know its time to ask, what is wrong my pro mini or the FTDI basic programmer. I check the serial monitor to see if it responds I don't get any response and after I used this I tried burning sketch and bootloader through my uno witch always works but neither worked saying I connected something wrong but its the same as I always had it and tried as many possibilities I can and nothing worked. My FTDI drivers are up to date and my computer says it is working fine. So I really dont know what to do anymore. Any ideas will be appreciated.
thanks
 
2  Using Arduino / Project Guidance / Re: Making a button switch codes? on: May 19, 2011, 02:03:41 pm
OK, time to learn how to post code so that you don't hospitalise other forum members with sprained scrolling fingers.

When you post some code, open a code box using the # icon on the editor's toolbar, then copy your code into the space between the tags. (you can do this retrospectively, by clicking on "modify" on each of your posts, highlighting the code, then clicking the # icon. (HINT))


Sorry about that I was trying to figure that out but couldn't find it. thanks for the tip.

some of my files were deleted and tried to figure out my sketch but got lost so I'm starting fresh. with the original codes I used.

Here is my 3 codes, 1 is for basic button setup, the second is the controlling rgb with potentiometer, and third is just automatic rainbow fade.

I tried last time mixing them together and switching some of the words to match like GREEN_LED_PIN to gpin, or is doing that wrong.

Yes I am new and a complete noob to writing sketches, but I want to learn really bad and I really appreciate the help and patience you all give me.

What do I do exactly to get started here?

Code:

int inPin = 2;         // the number of the input pin
int outPin = 13;       // the number of the output pin

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
}

void loop()
{
  reading = digitalRead(inPin);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();   
  }

  digitalWrite(outPin, state);

  previous = reading;
}

second

Code:
int potpin = 2;              // Switch connected to digital pin 2

int rpin = 9;
int gpin = 10;
int bpin = 11;
float h;
int h_int;
int r=0, g=0, b=0;

int val=0;

void h2rgb(float h, int &R, int &G, int &B);

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
}


void loop()                     // run over and over again
{
  val=analogRead(potpin);    // Read the pin and display the value
  //Serial.println(val);
  h = ((float)val)/1024;
  h_int = (int) 360*h;
  h2rgb(h,r,g,b);
  Serial.print("Potentiometer value: ");
  Serial.print(val);
  Serial.print(" = Hue of ");
  Serial.print(h_int);
  Serial.print("degrees. In RGB this is: ");
  Serial.print(r);
  Serial.print(" ");
  Serial.print(g);
  Serial.print(" ");
  Serial.println(b);

  analogWrite(rpin, r);
  analogWrite(gpin, g);
  analogWrite(bpin, b);
}

void h2rgb(float H, int& R, int& G, int& B) {

  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )                       //HSV values = 0 ÷ 1
  {
    R = V * 255;
    G = V * 255;
    B = V * 255;
  }
  else
  {
    var_h = H * 6;
    if ( var_h == 6 ) var_h = 0;      //H must be < 1
    var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    R = (1-var_r) * 255;                  //RGB results = 0 ÷ 255
    G = (1-var_g) * 255;
    B = (1-var_b) * 255;
  }
}
 

Third
Code:
// LED leads connected to PWM pins
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BLUE_LED_PIN = 11;

// Used to store the current intensity level of the individual LEDs
int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;

// Length of time we spend showing each color
const int DISPLAY_TIME = 100; // In milliseconds


void setup() {
  // No setup required.
}

void loop() {
  // Cycle color from red through to green
  // (In this loop we move from 100% red, 0% green to 0% red, 100% green)
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5) {
        redIntensity = 255-greenIntensity;
        analogWrite(GREEN_LED_PIN, greenIntensity);
        analogWrite(RED_LED_PIN, redIntensity);
        delay(DISPLAY_TIME);
  }

  // Cycle color from green through to blue
  // (In this loop we move from 100% green, 0% blue to 0% green, 100% blue) 
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5) {
        greenIntensity = 255-blueIntensity;
        analogWrite(BLUE_LED_PIN, blueIntensity);
        analogWrite(GREEN_LED_PIN, greenIntensity);
        delay(DISPLAY_TIME);
  }

  // Cycle cycle from blue through to red
  // (In this loop we move from 100% blue, 0% red to 0% blue, 100% red)   
  for (redIntensity = 0; redIntensity <= 255; redIntensity+=5) {
        blueIntensity = 255-redIntensity;
        analogWrite(RED_LED_PIN, redIntensity);
        analogWrite(BLUE_LED_PIN, blueIntensity);
        delay(DISPLAY_TIME);
  }
}
3  Using Arduino / Project Guidance / Re: Making a button switch codes? on: May 18, 2011, 09:45:28 pm
I made this sketch it loads fine but I'm not getting a response at all from the chip. What did I do wrong in it.

int buttonPin = 2;

int potpin = 3;

int rpin = 9;
int gpin = 10;
int bpin = 11;
float h;
int h_int;
int r=0, g=0, b=0;

int val;
int val2;
int buttonState;

int lightMode = 0;

const int DISPLAY_TIME = 100; // In milliseconds

void setup() {
  pinMode(rpin, OUTPUT);
  pinMode(gpin, OUTPUT);
  pinMode(bpin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  buttonState = digitalRead(buttonPin);
}

void loop() {
 val = digitalRead(buttonPin);      // read input value and store it in val
  delay(10);                         // 10 milliseconds is a good amount of time
  val2 = digitalRead(buttonPin);     // read the input again to check for bounces
  if (val == val2) {                 // make sure we got 2 consistant readings!
    if (val != buttonState) {          // the button state has changed!
      if (val == LOW) {                // check if the button is pressed
        if (lightMode == 0) {          // is the light off?
          lightMode = 1;
    digitalWrite(rpin, HIGH);
    digitalWrite(gpin, HIGH);
    digitalWrite(bpin, HIGH);
  // Cycle color from red through to green
  // (In this loop we move from 100% red, 0% green to 0% red, 100% green)
  for (g = 0; g <= 255; g+=5) {
        r = 255-g;
        analogWrite(gpin, g);
        analogWrite(rpin, r);
        delay(DISPLAY_TIME);
  }

  // Cycle color from green through to blue
  // (In this loop we move from 100% green, 0% blue to 0% green, 100% blue) 
  for (b = 0; b <= 255; b+=5) {
        g = 255-b;
        analogWrite(bpin, b);
        analogWrite(gpin, g);
        delay(DISPLAY_TIME);
  }

  // Cycle cycle from blue through to red
  // (In this loop we move from 100% blue, 0% red to 0% blue, 100% red)   
  for (r = 0; r <= 255; r+=5) {
        b = 255-r;
        analogWrite(rpin, r);
        analogWrite(bpin, b);
        delay(DISPLAY_TIME);
  }
}else {
  lightMode = 0;
    digitalWrite(rpin, LOW);
    digitalWrite(gpin, LOW);
    digitalWrite(bpin, LOW);
  {
   val=analogRead(potpin);    // Read the pin and display the value
  //Serial.println(val);
  h = ((float)val)/1024;
  h_int = (int) 360*h;

  Serial.print("Potentiometer value: ");
  Serial.print(val);
  Serial.print(" = Hue of ");
  Serial.print(h_int);
  Serial.print("degrees. In RGB this is: ");
  Serial.print(r);
  Serial.print(" ");
  Serial.print(g);
  Serial.print(" ");
  Serial.println(b);

  analogWrite(rpin, r);
  analogWrite(gpin, g);
  analogWrite(bpin, b);
}
{


  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )                       //HSV values = 0 ÷ 1
  {
    r = V * 255;
    g = V * 255;
    b = V * 255;
  }
  else
  {
    var_h = h * 6;
    if ( var_h == 6 ) var_h = 0;      //H must be < 1
    var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    r = (1-var_r) * 255;                  //RGB results = 0 ÷ 255
    g = (1-var_g) * 255;
    b = (1-var_b) * 255;
  }
}
}
buttonState = val;
      }
}}}


4  Using Arduino / Project Guidance / Re: Making a button switch codes? on: May 18, 2011, 06:50:05 pm
lol i don"t even know, but when I deleted it, the code works. thanks for pointing that out.
5  Using Arduino / Project Guidance / Re: Making a button switch codes? on: May 18, 2011, 06:05:35 pm
how do I write h2rgb

and where do I put it I cant figure it out
6  Using Arduino / Project Guidance / Re: Making a button switch codes? on: May 18, 2011, 05:55:39 pm
alright I got this but all it says is error compiling    undefined reference to h2rgb(float, int&, int&, int&)'

int buttonPin = 2;
int buttonState = 0;
int potpin = 3;

int rpin = 9;
int gpin = 10;
int bpin = 11;
float h;
int h_int;
int r=0, g=0, b=0;

int val = 0;


void h2rgb(float h, int &R, int &G, int &B);
// Length of time we spend showing each color
const int DISPLAY_TIME = 100; // In milliseconds


void setup() {
  pinMode(rpin, OUTPUT);
  pinMode(gpin, OUTPUT);
  pinMode(bpin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  buttonState = digitalRead(buttonPin);
 
  if (buttonState ==HIGH) {
  // Cycle color from red through to green
  // (In this loop we move from 100% red, 0% green to 0% red, 100% green)
  for (g = 0; g <= 255; g+=5) {
        r = 255-g;
        analogWrite(gpin, g);
        analogWrite(rpin, r);
        delay(DISPLAY_TIME);
  }

  // Cycle color from green through to blue
  // (In this loop we move from 100% green, 0% blue to 0% green, 100% blue) 
  for (b = 0; b <= 255; b+=5) {
        g = 255-b;
        analogWrite(bpin, b);
        analogWrite(gpin, g);
        delay(DISPLAY_TIME);
  }

  // Cycle cycle from blue through to red
  // (In this loop we move from 100% blue, 0% red to 0% blue, 100% red)   
  for (r = 0; r <= 255; r+=5) {
        b = 255-r;
        analogWrite(rpin, r);
        analogWrite(bpin, b);
        delay(DISPLAY_TIME);
  }
}
else {
{
   val=analogRead(potpin);    // Read the pin and display the value
  //Serial.println(val);
  h = ((float)val)/1024;
  h_int = (int) 360*h;
  h2rgb(h,r,g,b);
  Serial.print("Potentiometer value: ");
  Serial.print(val);
  Serial.print(" = Hue of ");
  Serial.print(h_int);
  Serial.print("degrees. In RGB this is: ");
  Serial.print(r);
  Serial.print(" ");
  Serial.print(g);
  Serial.print(" ");
  Serial.println(b);

  analogWrite(rpin, r);
  analogWrite(gpin, g);
  analogWrite(bpin, b);
}

void h2rgb(float H, int &R, int &G, int &B);

  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )                       //HSV values = 0 ÷ 1
  {
    r = V * 255;
    g = V * 255;
    b = V * 255;
  }
  else
  {
    var_h = h * 6;
    if ( var_h == 6 ) var_h = 0;      //H must be < 1
    var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    r = (1-var_r) * 255;                  //RGB results = 0 ÷ 255
    g = (1-var_g) * 255;
    b = (1-var_b) * 255;
  }
}
}
7  Using Arduino / Project Guidance / Re: Making a button switch codes? on: May 18, 2011, 04:29:46 pm
I made this sketch I don't know if its right but i get an error expected '{' at the end of input and highlights "void h2rgb(float H, int &R, int &G, int &B)"


 
  • int buttonPin = 2;
    int buttonState = 0;
    int potpin = 3;

    int rpin = 9;
    int gpin = 10;
    int bpin = 11;
    float h;
    int h_int;
    int r=0, g=0, b=0;

    int val = 0;


    void h2rgb(float h, int &R, int &G, int &B);
    // Length of time we spend showing each color
    const int DISPLAY_TIME = 100; // In milliseconds


    void setup() {
      pinMode(rpin, OUTPUT);
      pinMode(gpin, OUTPUT);
      pinMode(bpin, OUTPUT);
      pinMode(buttonPin, INPUT);
      Serial.begin(9600);
    }

    void loop() {
      buttonState = digitalRead(buttonPin);
     
      if (buttonState ==HIGH) {
      // Cycle color from red through to green
      // (In this loop we move from 100% red, 0% green to 0% red, 100% green)
      for (g = 0; g <= 255; g+=5) {
            r = 255-g;
            analogWrite(gpin, g);
            analogWrite(rpin, r);
            delay(DISPLAY_TIME);
      }

      // Cycle color from green through to blue
      // (In this loop we move from 100% green, 0% blue to 0% green, 100% blue) 
      for (b = 0; b <= 255; b+=5) {
            g = 255-b;
            analogWrite(bpin, b);
            analogWrite(gpin, g);
            delay(DISPLAY_TIME);
      }

      // Cycle cycle from blue through to red
      // (In this loop we move from 100% blue, 0% red to 0% blue, 100% red)   
      for (r = 0; r <= 255; r+=5) {
            b = 255-r;
            analogWrite(rpin, r);
            analogWrite(bpin, b);
            delay(DISPLAY_TIME);
      }
    }
    else {
    {
       val=analogRead(potpin);    // Read the pin and display the value
      //Serial.println(val);
      h = ((float)val)/1024;
      h_int = (int) 360*h;
      h2rgb(h,r,g,b);
      Serial.print("Potentiometer value: ");
      Serial.print(val);
      Serial.print(" = Hue of ");
      Serial.print(h_int);
      Serial.print("degrees. In RGB this is: ");
      Serial.print(r);
      Serial.print(" ");
      Serial.print(g);
      Serial.print(" ");
      Serial.println(b);

      analogWrite(rpin, r);
      analogWrite(gpin, g);
      analogWrite(bpin, b);
    }
    {
    void h2rgb(float H, int &R, int &G, int &B) {

      int var_i;
      float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

      if ( S == 0 )                       //HSV values = 0 ÷ 1
      {
        R = V * 255;
        G = V * 255;
        B = V * 255;
      }
      else
      {
        var_h = H * 6;
        if ( var_h == 6 ) var_h = 0;      //H must be < 1
        var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
        var_1 = V * ( 1 - S );
        var_2 = V * ( 1 - S * ( var_h - var_i ) );
        var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

        if      ( var_i == 0 ) {
          var_r = V     ;
          var_g = var_3 ;
          var_b = var_1 ;
        }
        else if ( var_i == 1 ) {
          var_r = var_2 ;
          var_g = V     ;
          var_b = var_1 ;
        }
        else if ( var_i == 2 ) {
          var_r = var_1 ;
          var_g = V     ;
          var_b = var_3 ;
        }
        else if ( var_i == 3 ) {
          var_r = var_1 ;
          var_g = var_2 ;
          var_b = V     ;
        }
        else if ( var_i == 4 ) {
          var_r = var_3 ;
          var_g = var_1 ;
          var_b = V     ;
        }
        else                   {
          var_r = V     ;
          var_g = var_1 ;
          var_b = var_2 ;
        }

        R = (1-var_r) * 255;                  //RGB results = 0 ÷ 255
        G = (1-var_g) * 255;
        B = (1-var_b) * 255;
      }
    }
    }
     
8  Using Arduino / Project Guidance / Re: Making a button switch codes? on: May 18, 2011, 03:01:18 pm

Create a variable to count the number of presses. When the number is even, do one thing. When it is odd, do the other thing.
[/quote]

How do I do that?
9  Using Arduino / Project Guidance / Making a button switch codes? on: May 18, 2011, 01:45:27 pm
I was wondering if there is a way to make a button switch from one code to the other.  I'm trying to make a lamp that switches from a potentiometer controlling an RGB LED to a rainbow mode that repeats itself when I press the button.  Any Ideas that may get me jump started on doing this would be great.
10  Using Arduino / Installation & Troubleshooting / Re: I think I messed up bad. on: May 17, 2011, 02:10:29 pm
Thanks

I'm self teaching, shit happens.
11  Using Arduino / Installation & Troubleshooting / I think I messed up bad. on: May 17, 2011, 12:32:27 pm
I had a board to solder my atmega 328 tqfp and as i was soldering i put what i thought was a little drop of solder and when i dabbed it on BLAM all the connections on one side were all one, i tried to desolder it but theres still a little bit of solder that i cant get and is connecting the pins still, I need help on getting that little bit out. Also I think maybe spending about 15 minutes reheating the solder in the chip so many times i think i may have fried the chip ( I was just thinking that may have happen by something inside maybe melting, I haven't tested the chip out yet). I would greatly appreciate your help thanks.
12  Using Arduino / Microcontrollers / Re: Programming ATtiny13? on: May 12, 2011, 05:39:48 pm
I couldn't find anything for attinny13, or does selecting attinny85 or 45 allow me to program the attinny13?
13  Using Arduino / Microcontrollers / Programming ATtiny13? on: May 12, 2011, 01:39:30 am
I'm trying to program an ATtiny13 through the arduino uno but theres a problem, theres no option to select ATtiny13 on arduino sketch program, does anyone know or have the file I need to get ATtiny13 to show up, I believe you put the file in the hardware folder.
14  Using Arduino / Microcontrollers / Re: What are my PIC options for UNO? on: April 28, 2011, 03:03:49 pm
I'm guessing from your question that you don't know what an "AVR processor" is.

The Arduino is based on Atmel AVR 8 bit processors.  As far as I know, there is very very little Arduino support for Microchip PIC processors.  The bad news is that you will have a difficult time using Arduino software or hardware with a PIC processor.

The good news is that whatever you are trying to accomplish with a PIC processor you will very likely be able to do with an AVR processor.

In other words, I suggest that you focus less on the processor vendor (Microchip versus Atmel) and more on what you want to accomplish (and resign yourself to using Atmel  smiley-grin).


 I get it things are clearer now, thanks!
15  Using Arduino / Microcontrollers / Re: What are my PIC options for UNO? on: April 28, 2011, 02:18:08 pm
So if i connect the right pins to another board like a breadboard with any PIC on it I can program it through the uno board?
Pages: [1] 2