Arduino- Not outputting 2 separate signals

by Neamus   Last Updated August 14, 2019 08:25 AM

I’m trying to get an Arduino to output 2 signals with different frequencies for a project.The schematic of the circuit is shown below.

I’m trying to experiment using Pulse Width Modulation to give me a constant signal (the code is similar to dimming an LED). Long story short, when the Arduino powers on the LED connect to ~9 flashes at a constant frequency (I still need to find out the frequency using a scope) and ~10 doesn’t flash at all. Once the button is* pressed* ~9 stops blinking, ~10 blinks for 30ms and ~9 starts blinking again.

So, my question is there a way I can get 2 signals to be outputted from an Arduino and somehow adjust the frequency of one of the outputs by changing a number (like ‘freq (1000)’ for 1 kHz).

Thank-you to all in advance,

~Neamus

//le code

int frequency = 0;
int milli = 10;
int milli2 = 30;
const int button = 2; 

int buttonState = 0;  

void setup()
{
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(button, INPUT_PULLUP);
}

void loop()
{
  buttonState = digitalRead(button);
  for (frequency = 0; frequency <= 255; frequency += 127) {
    analogWrite(9, frequency);
    delay(milli); // Wait for 30 millisecond(s)
 }
  for (frequency = 255; frequency >= 0; frequency -= 127) {
    analogWrite(9, frequency);
    delay(milli); // Wait for 30 millisecond(s)
  }

   if (buttonState == LOW) {
    for (frequency = 0; frequency <= 255; frequency += 127) {
      analogWrite(10, frequency);
      delay(milli2);
 }
     for (frequency = 255; frequency >= 0; frequency -= 127) {
    analogWrite(10, frequency);
    delay(milli2); 
    } 
   }
  }

Schematic



Related Questions


Updated June 14, 2017 07:25 AM

Updated February 02, 2017 14:10 PM

Updated March 02, 2017 01:25 AM

Updated March 26, 2016 08:10 AM