Hello, I am trying to half the output power of a motor control program I wrote a while ago which uses PWM pins. I wanted to do this by just changing the PWM resolution from 8 bits (255) to 9 bits (511) which should do the trick I would think, instead of going through the code and dividing everything by 2 or adding a function that does it before the outputs are applied. When I tried using the “analogWriteResolution()” command I got an error message saying " ‘analogWriteResolution()’ was not declared in this scope’ " this got me curious and I have been trying to solve the problem with no avail. I have included the code for the driver tester program I was going to use, with the error messages, as an example.
I am using an Arduino Mega 2560 Rev 3. It is not currently in my possession and so is not plugged in. I was just going to write a program and compile it then test it when I can, does this affect anything?
I tried using different versions of Arduino, 1.01 and 1.05 and both produce the same error messages.
I even tried adding ’ #include “Arduino.h” ’ but that did nothing.
I have tried searching for the answer on my own but I havent been able to find anything useful, so could you guys help me please?
#include "Arduino.h"
void setup(){
Serial.begin(9600);
for(int x = 0 ; x < 7; x++){
pinMode(x, OUTPUT);
}
}
void loop(){
analogWriteResolution(9); //Change PWM resolution to 0-511
int FULL_PIN = 2; //Full power pin
int HALF_PIN = 3; //Half power pin
int OSCI_PIN = 4; //Oscilating pin (Triangular wave)
int DIR_PIN = 5; //Direction pin (HIGH = reverse; LOW = forward)
int HALF_POWER = 255;
//Produce constant FULL and HALF power (using PWM) pins
digitalWrite(FULL_PIN, HIGH);
analogWrite(HALF_PIN, HALF_POWER);
[more code]
}
Error Messages
Driver_tester2.ino: In function 'void loop()':
Driver_tester2:14: error 'analogWriteResolution' was not declared in this scope
‘analogWriteResolution()’ was not declared in this scope