Itsy Bitsy 32u4 5V analogWrite()

Hello,

I'm very new to Arduino and I'm trying to figure out proper usage for analogWrite(). I just bought an Itsy Bitsy 32u4 and I'm trying to write some very basic test code that I'll use to drive a tri-cree LED at some point, but right now, I'm just trying to get a single diode to work. The code I currently have doesn't seem to change the value of the pin - it stays fixed at around 150 when I view it in the serial monitor. When I power the board externally, the value drops to around 0. Not really sure what's going on so any help would be appreciated. Thanks!

image

Hey, I'm new too. When you analogWrite you need to use a value between 0 and 255, not HIGH or LOW.

Pinouts | Introducing ItsyBitsy 32u4 | Adafruit Learning System show which pins do what, if you haven't seen it.

Sadly, as a newbie, you’ve missed almost every metric for posting effectively

Wrong forum section.
No code tags,
and some other lesser offences… I hope it gets better.

You obviously haven’t played with the analogWrite examples - they might save you a lot of time

1 Like

Look at the Fade Example.

I don't know anything about the Itsy Bitsy 32u4 , but I'll trust that the pins you are using support PWM (analogWrite).

AnalogWrite isn't true analog, it's PWM which can "simulate" analog to make an LED appear dim, or to control motor speed.

You don't analogWrite() a high or low, you write a value between 0 and 256.

And, you can't read-back the value.

Thread moved as requested.

Thanks for the help! I've used the code from the fade example, but still no luck. Here's the pinout - not sure I'm using the right pins.

Please don't post images of code (or errors for that matter). What are you going to do when there are a few 100 lines of code?

The simple way to post code

  1. In the IDE, use tools -> autoformat; you seem to have used that or are a neat person who properly indents :wink:
  2. In the IDE, use edit -> copy for forum; this will place a copy on the clipboard including so-called code tags.
  3. Paste the contents of the clipboard in a reply and save the reply.

Google works.......
https://learn.adafruit.com/introducting-itsy-bitsy-32u4/pinouts

Yep it does! That's where the image I attached is from originally. I'm attempting to explain that that's where my very little knowledge is coming from and it's not working. Any ideas as to what I'm doing wrong? I'm using pin 13 - any reason that doesn't make sense in this context?

"#13 - GPIO #13, can do PWM output and is connected to the red LED next to the Reset button"

So you should be able to watch the onboard LED to see your analogWrite().

Your bluePin, however, is connected to an ADC, and won't work as a PWM.

Okay cool. Thanks! So if I wanted three PWM pins for red, green, and blue, would it make sense to use 13, 11, and 7? Most of the PWM pins look like they're hooked up to some other function like interrupts, clocks, etc. so I'm not 100% sure what's available as just a set of basic PWM pins.

You can just move 12 to 9 or 10. The list of things each pin can do would be separate uses for that pin, not other things happening at the same time. For instance, pin 3 can act as a PWM or interrupt (among other things), but you have to pick one when you set the pinMode. Any of the ones that say PWM output will work for what you are doing. Pin 7 is not a PWM.

1 Like

You asked what pins drive analogout (pwm) and I showed you the page where it was clearly stated.
If you had that already, then (just guessing mind you) that you didn't read the detail properly.

Looking at the image in reply #6, pin 7 does not provide PWM.

When designing a project, you will have to take into account what you all need. E.g. if you have to use I2C for a sensor or I2C display, you can't use pin 3 for PWM because it will be used for SCL (one of the two I2C signals).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.