Go Down

Topic: Scepter prop for HS Drama (Read 110 times) previous topic - next topic

rabidgeek

Apr 17, 2019, 09:40 pm Last Edit: Apr 18, 2019, 04:15 am by rabidgeek
Hey -

I'm using a pro mini 5v/16mhz, which is connected to a pushbutton (via 10k resistor) and one RGB LED. I tested my code initially on an Uno, and everything works as I wanted it to. I need to use the pro mini because of its small size, so I finally transferred my code to a pro mini after testing the blink schematic on it (works fine!). However, with the FTDI cable OR LiPO battery (from adafruit, 2000 mAh 3.7v) it doesn't turn on the LED at all! What's going on? I even wired two of these batteries in serial for 7.4v and still no go. Code is below. All the wires are in their proper places - I double checked the pins and all is good.

-----------------------
Code: [Select]

const int redPin = 12;
const int greenPin = 11;
const int bluePin = 10;
const int buttonPin = 9;`

int counter = 0;
int buttonState = 0;
int lastState = 0;

#define COMMON_ANODE

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(buttonPin, INPUT);
  //Serial.begin(9600);
}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonState != lastState) {
    if (buttonState == HIGH) {
      counter++;
      //Serial.println("on");
      //Serial.print("number of button pushes: ");
      //Serial.println(counter);
    //} else {
      //Serial.println("off");
    }
    delay(50);
  }

  lastState = buttonState;
 
  if (counter == 1) {
    orange();
  } else  if (counter == 2) {
    red();
  } else if (counter == 3) {
    purple();
  } else {
    off();
  }

  if (counter > 3)
    counter = 0;
}

void off() {
  analogWrite(redPin, 0);
  analogWrite(bluePin, 0);
  analogWrite(greenPin, 0);
}

void purple() {
  setColor(153, 51, 255);
}

void red() {
  setColor(255, 0, 0);
}
void orange() {
    setColor(255, 90, 80); // orange
}

void setColor(int red, int green, int blue) {
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

groundFungus

Please post a schematic of the project.  If you uncomment the serial prints, what do you get in serial monitor?

Post code in code tags as described in the how to use this forum-please read stickies.

rabidgeek

done.

using the uno, I get a count of how many times the button is pressed. I read the pro mini doesnt have serial communication, so I uncommented that for the pro mini upload.

on the RGB LED, the long wire goes to VCC. the other 3 go to pins 10, 11, and 12. for the pushbutton, one goes to a 10k resistor, which is wired to GND, one is wired to VCC, and one is wired to pin 9.

I don't get why it works fine on the uno, but not the pro mini. Can't be due to a lack of power?

Go Up