A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-docs/latest/lang/api/pwmwrite.html below:

pwmWrite() — Maple v0.0.12 Documentation

pwmWrite()¶

Writes a PWM wave to a pin. You can use this to make an LED get brighter or dimmer, control a servomotor, etc. After a call to pwmWrite(), the pin will output a steady square wave with the given duty cycle. You can change the duty cycle later by calling pwmWrite() again with the same pin and a different duty.

The pins which support PWM have PWM listed underneath their number on your board’s silkscreen. These pin numbers are available to your program in the boardPWMPins board-specific array. The number of pins which are capable of PWM on your board is given by the BOARD_NR_PWM_PINS constant. These values are documented for each board in the Board Hardware Documentation pages.

The Arduino function analogWrite() is an alias for pwmWrite(), but it is badly named, and its use is discouraged.

Library Documentation¶

void pwmWrite(uint8 pin, uint16 duty_cycle)

Set the PWM duty on the given pin.

User code is expected to determine and honor the maximum value (based on the configured period).

Parameters:
Example¶

Sets the output to the LED proportional to the value read from the potentiometer:

int analogPin = 3;    // potentiometer connected to analog pin 3

void setup() {
  pinMode(BOARD_LED_PIN, OUTPUT);   // sets the LED pin as output

  pinMode(analogPin, INPUT_ANALOG); // sets the potentiometer pin as
                                    // analog input
}

void loop() {
  int val = analogRead(analogPin);        // read the input pin

  pwmWrite(BOARD_LED_PIN, val * 16);  // analogRead values go from 0
                                      // to 4095, pwmWrite values
                                      // from 0 to 65535, so scale roughly
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4