Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

Program on Arduino not working on Metro Board
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Program on Arduino not working on Metro Board

by Bubby0626 on Wed Jan 26, 2022 4:58 pm

So I have been able to execute the program on the Arduino Uno below. Basically what the program does is turn on these LEDs/motors (I've been using LEDs) in an on/off pattern while being able to be controlled by a potentiometer. When I tried it on the Metro, I have no trouble compiling it, but it doesn't work at all. Would someone know why this is happening?

Code:

Code: Select all | TOGGLE FULL SIZE
#define LED_1_PIN 5
#define LED_2_PIN 6
#define LED_3_PIN 3
#define LED_4_PIN 9
#define LED_5_PIN 10
#define LED_6_PIN 11
const int potPin = A0;
int readValue = 0;
int writeValue;
int brightness = 0;
int motorState = 0;

int inputVal = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(potPin, INPUT);
  pinMode(LED_1_PIN, OUTPUT);
  pinMode(LED_2_PIN, OUTPUT);
  pinMode(LED_3_PIN, OUTPUT);
  pinMode(LED_4_PIN, OUTPUT);
  pinMode(LED_5_PIN, OUTPUT);
  pinMode(LED_6_PIN, OUTPUT);
}

void Potentiometer()
{
  readValue = analogRead(potPin);
  brightness = (255./1023.) * readValue;
  if (readValue > 0)
  {
    vibrate();
  }
}

void vibrate()
{
  if(motorState == 0) {
    analogWrite(LED_1_PIN, brightness);
    analogWrite(LED_2_PIN, brightness);
    analogWrite(LED_3_PIN, brightness);
    analogWrite(LED_4_PIN, 0);
    analogWrite(LED_5_PIN, 0);
    analogWrite(LED_6_PIN, 0);

    motorState = motorState + 1;
  }
  else if(motorState == 1)
  {
    analogWrite(LED_1_PIN, 0);
    analogWrite(LED_2_PIN, 0);
    analogWrite(LED_3_PIN, 0);
    analogWrite(LED_4_PIN, brightness);
    analogWrite(LED_5_PIN, brightness);
    analogWrite(LED_6_PIN, brightness);

    motorState = 0;
  }
}

void loop()
{
  static unsigned long previousMillis = 0;
  if (millis() - previousMillis >= 500)
  {
    previousMillis += 500;
   Potentiometer();
  }
}

Bubby0626
 
Posts: 4
Joined: Mon Nov 22, 2021 5:53 pm

Re: Program on Arduino not working on Metro Board

by dastels on Wed Jan 26, 2022 6:57 pm

Is your board setting correct?

Dave

dastels
 
Posts: 9768
Joined: Tue Oct 20, 2015 3:22 pm

Re: Program on Arduino not working on Metro Board

by mikeysklar on Wed Jan 26, 2022 6:59 pm

Which model of the Adafruit Metro are you using?

mikeysklar
 
Posts: 7564
Joined: Mon Aug 01, 2016 8:10 pm

Re: Program on Arduino not working on Metro Board

by RogierWeekers on Thu Jan 27, 2022 2:55 am

Maybe your calculation is wrong.
brightness = (255./1023.) * readValue;

analogRead gives a 12 bit (max 4095) value, and i would cast readValue to float before calculation to make sure it is not treated as an integer.

brightness = (255.0/4096.0) * (float) readvalue

RogierWeekers
 
Posts: 6
Joined: Wed Jan 26, 2022 8:43 pm

Re: Program on Arduino not working on Metro Board

by dastels on Thu Jan 27, 2022 8:03 am

Good catch. The '328 has 10-bit ADCs. If you have a SAMD based Metro, the ADCs are 12 bit.

Dave

dastels
 
Posts: 9768
Joined: Tue Oct 20, 2015 3:22 pm

Re: Program on Arduino not working on Metro Board

by mikeysklar on Thu Jan 27, 2022 1:49 pm

SAMD Metros would also be 3v3 based so possibly some wiring changes are needed. Still don't know which model of Metro is being used here.

mikeysklar
 
Posts: 7564
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.