A simple 128x32 graphical LCD program to quickstart with LCD on ARM mbed IoT Starter Kit. This requires mbed Applciation Shield with FRDM-K64F platform.

Dependencies:   C12832

Committer:
tushki7
Date:
Sun Apr 12 15:45:52 2015 +0000
Revision:
1:eb68c94a8ee5
Parent:
0:60d829a0353a
A simple 128x32 LCD program with ARM mbed IoT Starter Kit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tushki7 0:60d829a0353a 1 /* mbed Microcontroller Library
tushki7 0:60d829a0353a 2 * Copyright (c) 2006-2013 ARM Limited
tushki7 0:60d829a0353a 3 *
tushki7 0:60d829a0353a 4 * Licensed under the Apache License, Version 2.0 (the "License");
tushki7 0:60d829a0353a 5 * you may not use this file except in compliance with the License.
tushki7 0:60d829a0353a 6 * You may obtain a copy of the License at
tushki7 0:60d829a0353a 7 *
tushki7 0:60d829a0353a 8 * http://www.apache.org/licenses/LICENSE-2.0
tushki7 0:60d829a0353a 9 *
tushki7 0:60d829a0353a 10 * Unless required by applicable law or agreed to in writing, software
tushki7 0:60d829a0353a 11 * distributed under the License is distributed on an "AS IS" BASIS,
tushki7 0:60d829a0353a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tushki7 0:60d829a0353a 13 * See the License for the specific language governing permissions and
tushki7 0:60d829a0353a 14 * limitations under the License.
tushki7 0:60d829a0353a 15 */
tushki7 0:60d829a0353a 16 #ifndef MBED_PWMOUT_H
tushki7 0:60d829a0353a 17 #define MBED_PWMOUT_H
tushki7 0:60d829a0353a 18
tushki7 0:60d829a0353a 19 #include "platform.h"
tushki7 0:60d829a0353a 20
tushki7 0:60d829a0353a 21 #if DEVICE_PWMOUT
tushki7 0:60d829a0353a 22 #include "pwmout_api.h"
tushki7 0:60d829a0353a 23
tushki7 0:60d829a0353a 24 namespace mbed {
tushki7 0:60d829a0353a 25
tushki7 0:60d829a0353a 26 /** A pulse-width modulation digital output
tushki7 0:60d829a0353a 27 *
tushki7 0:60d829a0353a 28 * Example
tushki7 0:60d829a0353a 29 * @code
tushki7 0:60d829a0353a 30 * // Fade a led on.
tushki7 0:60d829a0353a 31 * #include "mbed.h"
tushki7 0:60d829a0353a 32 *
tushki7 0:60d829a0353a 33 * PwmOut led(LED1);
tushki7 0:60d829a0353a 34 *
tushki7 0:60d829a0353a 35 * int main() {
tushki7 0:60d829a0353a 36 * while(1) {
tushki7 0:60d829a0353a 37 * led = led + 0.01;
tushki7 0:60d829a0353a 38 * wait(0.2);
tushki7 0:60d829a0353a 39 * if(led == 1.0) {
tushki7 0:60d829a0353a 40 * led = 0;
tushki7 0:60d829a0353a 41 * }
tushki7 0:60d829a0353a 42 * }
tushki7 0:60d829a0353a 43 * }
tushki7 0:60d829a0353a 44 * @endcode
tushki7 0:60d829a0353a 45 *
tushki7 0:60d829a0353a 46 * @note
tushki7 0:60d829a0353a 47 * On the LPC1768 and LPC2368, the PWMs all share the same
tushki7 0:60d829a0353a 48 * period - if you change the period for one, you change it for all.
tushki7 0:60d829a0353a 49 * Although routines that change the period maintain the duty cycle
tushki7 0:60d829a0353a 50 * for its PWM, all other PWMs will require their duty cycle to be
tushki7 0:60d829a0353a 51 * refreshed.
tushki7 0:60d829a0353a 52 */
tushki7 0:60d829a0353a 53 class PwmOut {
tushki7 0:60d829a0353a 54
tushki7 0:60d829a0353a 55 public:
tushki7 0:60d829a0353a 56
tushki7 0:60d829a0353a 57 /** Create a PwmOut connected to the specified pin
tushki7 0:60d829a0353a 58 *
tushki7 0:60d829a0353a 59 * @param pin PwmOut pin to connect to
tushki7 0:60d829a0353a 60 */
tushki7 0:60d829a0353a 61 PwmOut(PinName pin) {
tushki7 0:60d829a0353a 62 pwmout_init(&_pwm, pin);
tushki7 0:60d829a0353a 63 }
tushki7 0:60d829a0353a 64
tushki7 0:60d829a0353a 65 /** Set the ouput duty-cycle, specified as a percentage (float)
tushki7 0:60d829a0353a 66 *
tushki7 0:60d829a0353a 67 * @param value A floating-point value representing the output duty-cycle,
tushki7 0:60d829a0353a 68 * specified as a percentage. The value should lie between
tushki7 0:60d829a0353a 69 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
tushki7 0:60d829a0353a 70 * Values outside this range will be saturated to 0.0f or 1.0f.
tushki7 0:60d829a0353a 71 */
tushki7 0:60d829a0353a 72 void write(float value) {
tushki7 0:60d829a0353a 73 pwmout_write(&_pwm, value);
tushki7 0:60d829a0353a 74 }
tushki7 0:60d829a0353a 75
tushki7 0:60d829a0353a 76 /** Return the current output duty-cycle setting, measured as a percentage (float)
tushki7 0:60d829a0353a 77 *
tushki7 0:60d829a0353a 78 * @returns
tushki7 0:60d829a0353a 79 * A floating-point value representing the current duty-cycle being output on the pin,
tushki7 0:60d829a0353a 80 * measured as a percentage. The returned value will lie between
tushki7 0:60d829a0353a 81 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
tushki7 0:60d829a0353a 82 *
tushki7 0:60d829a0353a 83 * @note
tushki7 0:60d829a0353a 84 * This value may not match exactly the value set by a previous <write>.
tushki7 0:60d829a0353a 85 */
tushki7 0:60d829a0353a 86 float read() {
tushki7 0:60d829a0353a 87 return pwmout_read(&_pwm);
tushki7 0:60d829a0353a 88 }
tushki7 0:60d829a0353a 89
tushki7 0:60d829a0353a 90 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
tushki7 0:60d829a0353a 91 *
tushki7 0:60d829a0353a 92 * @note
tushki7 0:60d829a0353a 93 * The resolution is currently in microseconds; periods smaller than this
tushki7 0:60d829a0353a 94 * will be set to zero.
tushki7 0:60d829a0353a 95 */
tushki7 0:60d829a0353a 96 void period(float seconds) {
tushki7 0:60d829a0353a 97 pwmout_period(&_pwm, seconds);
tushki7 0:60d829a0353a 98 }
tushki7 0:60d829a0353a 99
tushki7 0:60d829a0353a 100 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
tushki7 0:60d829a0353a 101 */
tushki7 0:60d829a0353a 102 void period_ms(int ms) {
tushki7 0:60d829a0353a 103 pwmout_period_ms(&_pwm, ms);
tushki7 0:60d829a0353a 104 }
tushki7 0:60d829a0353a 105
tushki7 0:60d829a0353a 106 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
tushki7 0:60d829a0353a 107 */
tushki7 0:60d829a0353a 108 void period_us(int us) {
tushki7 0:60d829a0353a 109 pwmout_period_us(&_pwm, us);
tushki7 0:60d829a0353a 110 }
tushki7 0:60d829a0353a 111
tushki7 0:60d829a0353a 112 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
tushki7 0:60d829a0353a 113 */
tushki7 0:60d829a0353a 114 void pulsewidth(float seconds) {
tushki7 0:60d829a0353a 115 pwmout_pulsewidth(&_pwm, seconds);
tushki7 0:60d829a0353a 116 }
tushki7 0:60d829a0353a 117
tushki7 0:60d829a0353a 118 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
tushki7 0:60d829a0353a 119 */
tushki7 0:60d829a0353a 120 void pulsewidth_ms(int ms) {
tushki7 0:60d829a0353a 121 pwmout_pulsewidth_ms(&_pwm, ms);
tushki7 0:60d829a0353a 122 }
tushki7 0:60d829a0353a 123
tushki7 0:60d829a0353a 124 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
tushki7 0:60d829a0353a 125 */
tushki7 0:60d829a0353a 126 void pulsewidth_us(int us) {
tushki7 0:60d829a0353a 127 pwmout_pulsewidth_us(&_pwm, us);
tushki7 0:60d829a0353a 128 }
tushki7 0:60d829a0353a 129
tushki7 0:60d829a0353a 130 #ifdef MBED_OPERATORS
tushki7 0:60d829a0353a 131 /** A operator shorthand for write()
tushki7 0:60d829a0353a 132 */
tushki7 0:60d829a0353a 133 PwmOut& operator= (float value) {
tushki7 0:60d829a0353a 134 write(value);
tushki7 0:60d829a0353a 135 return *this;
tushki7 0:60d829a0353a 136 }
tushki7 0:60d829a0353a 137
tushki7 0:60d829a0353a 138 PwmOut& operator= (PwmOut& rhs) {
tushki7 0:60d829a0353a 139 write(rhs.read());
tushki7 0:60d829a0353a 140 return *this;
tushki7 0:60d829a0353a 141 }
tushki7 0:60d829a0353a 142
tushki7 0:60d829a0353a 143 /** An operator shorthand for read()
tushki7 0:60d829a0353a 144 */
tushki7 0:60d829a0353a 145 operator float() {
tushki7 0:60d829a0353a 146 return read();
tushki7 0:60d829a0353a 147 }
tushki7 0:60d829a0353a 148 #endif
tushki7 0:60d829a0353a 149
tushki7 0:60d829a0353a 150 protected:
tushki7 0:60d829a0353a 151 pwmout_t _pwm;
tushki7 0:60d829a0353a 152 };
tushki7 0:60d829a0353a 153
tushki7 0:60d829a0353a 154 } // namespace mbed
tushki7 0:60d829a0353a 155
tushki7 0:60d829a0353a 156 #endif
tushki7 0:60d829a0353a 157
tushki7 0:60d829a0353a 158 #endif