PWM basic

What are you developing?
ted
Posts: 62
Joined: Sun Jul 16, 2017 9:57 pm

PWM basic

Post by ted » Fri Jan 05, 2018 9:34 pm

There must be a simple code for this circuit - sine in sine out. Any solution welcome.
Attachments
pwm1.jpg
pwm1.jpg (34.35 KiB) Viewed 332 times

dannyf
Posts: 228
Joined: Wed May 11, 2016 4:29 pm

Re: PWM basic

Post by dannyf » Fri Jan 05, 2018 11:27 pm

There must be a simple code for this circuit
yes:

1) connect the input to output;

2) run the following code in the mcu:

Code: Select all

  while (1) {
  }

ted
Posts: 62
Joined: Sun Jul 16, 2017 9:57 pm

Re: PWM basic

Post by ted » Sat Jan 06, 2018 1:54 am

This is what I did, the code and error. I know what error is saying, don't know how to fix it.

Code: Select all

input_output:17: error: 'Serial' does not name a type

 Serial.print(outputPin, value);

 ^

input_output:18: error: expected constructor, destructor, or type conversion before '(' token

 analogWrite(outputPin);

            ^

exit status 1
'Serial' does not name a type

Code: Select all

//analogWrite(outputpin);   analogRead(inputpin));
int inputPin  = PA6;  // analog input pin, inputPin = PB0;
int outputPin = PA7; //output pin
int analogOut;

void setup() {
  Serial.begin(115200);
  pinMode(inputPin, INPUT_ANALOG);
  pinMode(outputPin, OUTPUT);
  int8_t value = analogRead(inputPin);
}
void loop() {
  while (1) {
  }
}

Serial.print(outputPin, value);
analogWrite(outputPin);

stevestrong
Posts: 2049
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: PWM basic

Post by stevestrong » Sat Jan 06, 2018 8:26 am

Try this:

Code: Select all

pinMode(outputPin, PWM); // instead of OUTPUT
...
Serial.print(value);
analogWrite(outputPin, value);

ted
Posts: 62
Joined: Sun Jul 16, 2017 9:57 pm

Re: PWM basic

Post by ted » Sat Jan 06, 2018 5:41 pm

This is a new code and a new error.
input_output:26: error: expected constructor, destructor, or type conversion before '(' token

analogWrite(outputPin);

^

exit status 1
expected constructor, destructor, or type conversion before '(' token

Code: Select all


/*pinMode(outputPin, PWM); // instead of OUTPUT
...
Serial.print(value);
analogWrite(outputPin, value);*/

//analogWrite(outputpin);   analogRead(inputpin));
int inputPin  = PA6;  // analog input pin, inputPin = PB0;
int outputPin = PA7; //output pin
int analogOut;

void setup() {
  Serial.begin(115200);
  pinMode(inputPin, INPUT_ANALOG);
 // pinMode(outputPin, OUTPUT);
 pinMode(outputPin, PWM);
  int8_t value = analogRead(inputPin);
}
void loop() {
  while (1) {
  }
}



//Serial.print(outputPin, value);
analogWrite(outputPin);


User avatar
martinayotte
Posts: 1241
Joined: Mon Apr 27, 2015 1:45 pm

Re: PWM basic

Post by martinayotte » Sat Jan 06, 2018 5:47 pm

Why the analogWrite() is placed outside any scope ? ... :ugeek:

ted
Posts: 62
Joined: Sun Jul 16, 2017 9:57 pm

Re: PWM basic

Post by ted » Sat Jan 06, 2018 6:20 pm

this is a draft, I am using those lines to make code work, thanks for pointing that.
New code and new error.
input_output:3: error: 'Serial' does not name a type

Serial.print(value);

^

input_output:4: error: expected constructor, destructor, or type conversion before '(' token

analogWrite(outputPin, value);

^

exit status 1
'Serial' does not name a type

Code: Select all

/*pinMode(outputPin, PWM); // instead of OUTPUT
...*/
Serial.print(value);
analogWrite(outputPin, value);

//analogWrite(outputpin);   analogRead(inputpin));
int inputPin  = PA6;  // analog input pin, inputPin = PB0;
int outputPin = PA7; //output pin
int analogOut;

void setup() {
  Serial.begin(115200);
  pinMode(inputPin, INPUT_ANALOG);
 // pinMode(outputPin, OUTPUT);
 pinMode(outputPin, PWM);
  int8_t value = analogRead(inputPin);
}
void loop() {
  while (1) {
  }
}

//Serial.print(outputPin, value);
//analogWrite(outputPin);



User avatar
martinayotte
Posts: 1241
Joined: Mon Apr 27, 2015 1:45 pm

Re: PWM basic

Post by martinayotte » Sat Jan 06, 2018 6:34 pm

Again, you still have analogWrite() at line 4 outside any scope !
It must be inside either setup() or loop() ...

ted
Posts: 62
Joined: Sun Jul 16, 2017 9:57 pm

Re: PWM basic

Post by ted » Sat Jan 06, 2018 7:09 pm

The error comes from this line - Serial' does not name a type , mentioned line is disabled by //'

ted
Posts: 62
Joined: Sun Jul 16, 2017 9:57 pm

Re: PWM basic

Post by ted » Sat Jan 06, 2018 7:16 pm

new correction and error.
input_output:3: error: 'Serial' does not name a type

Serial.print(value);

^

input_output:4: error: expected constructor, destructor, or type conversion before '(' token

analogWrite(outputPin, value);

^

C:\Users\OWNER\Documents\Arduino\input_output\input_output.ino: In function 'void setup()':

input_output:14: error: 'outputpin' was not declared in this scope

analogWrite(outputpin);

^

exit status 1
'Serial' does not name a type

Code: Select all

/*pinMode(outputPin, PWM); // instead of OUTPUT
...*/
Serial.print(value);
analogWrite(outputPin, value);

//analogWrite(outputpin);   analogRead(inputpin));
int inputPin  = PA6;  // analog input pin, inputPin = PB0;
int outputPin = PA7; //output pin
int analogOut;

void setup() {
  Serial.begin(115200);
  pinMode(inputPin, INPUT_ANALOG);
  analogWrite(outputpin); 
 // pinMode(outputPin, OUTPUT);
 pinMode(outputPin, PWM);
  int8_t value = analogRead(inputPin);
}
void loop() {
  while (1) {
  }
}

//Serial.print(outputPin, value);
//analogWrite(outputPin);

Locked