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_ANALOGOUT_H
tushki7 0:60d829a0353a 17 #define MBED_ANALOGOUT_H
tushki7 0:60d829a0353a 18
tushki7 0:60d829a0353a 19 #include "platform.h"
tushki7 0:60d829a0353a 20
tushki7 0:60d829a0353a 21 #if DEVICE_ANALOGOUT
tushki7 0:60d829a0353a 22
tushki7 0:60d829a0353a 23 #include "analogout_api.h"
tushki7 0:60d829a0353a 24
tushki7 0:60d829a0353a 25 namespace mbed {
tushki7 0:60d829a0353a 26
tushki7 0:60d829a0353a 27 /** An analog output, used for setting the voltage on a pin
tushki7 0:60d829a0353a 28 *
tushki7 0:60d829a0353a 29 * Example:
tushki7 0:60d829a0353a 30 * @code
tushki7 0:60d829a0353a 31 * // Make a sawtooth output
tushki7 0:60d829a0353a 32 *
tushki7 0:60d829a0353a 33 * #include "mbed.h"
tushki7 0:60d829a0353a 34 *
tushki7 0:60d829a0353a 35 * AnalogOut tri(p18);
tushki7 0:60d829a0353a 36 * int main() {
tushki7 0:60d829a0353a 37 * while(1) {
tushki7 0:60d829a0353a 38 * tri = tri + 0.01;
tushki7 0:60d829a0353a 39 * wait_us(1);
tushki7 0:60d829a0353a 40 * if(tri == 1) {
tushki7 0:60d829a0353a 41 * tri = 0;
tushki7 0:60d829a0353a 42 * }
tushki7 0:60d829a0353a 43 * }
tushki7 0:60d829a0353a 44 * }
tushki7 0:60d829a0353a 45 * @endcode
tushki7 0:60d829a0353a 46 */
tushki7 0:60d829a0353a 47 class AnalogOut {
tushki7 0:60d829a0353a 48
tushki7 0:60d829a0353a 49 public:
tushki7 0:60d829a0353a 50
tushki7 0:60d829a0353a 51 /** Create an AnalogOut connected to the specified pin
tushki7 0:60d829a0353a 52 *
tushki7 0:60d829a0353a 53 * @param AnalogOut pin to connect to (18)
tushki7 0:60d829a0353a 54 */
tushki7 0:60d829a0353a 55 AnalogOut(PinName pin) {
tushki7 0:60d829a0353a 56 analogout_init(&_dac, pin);
tushki7 0:60d829a0353a 57 }
tushki7 0:60d829a0353a 58
tushki7 0:60d829a0353a 59 /** Set the output voltage, specified as a percentage (float)
tushki7 0:60d829a0353a 60 *
tushki7 0:60d829a0353a 61 * @param value A floating-point value representing the output voltage,
tushki7 0:60d829a0353a 62 * specified as a percentage. The value should lie between
tushki7 0:60d829a0353a 63 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
tushki7 0:60d829a0353a 64 * Values outside this range will be saturated to 0.0f or 1.0f.
tushki7 0:60d829a0353a 65 */
tushki7 0:60d829a0353a 66 void write(float value) {
tushki7 0:60d829a0353a 67 analogout_write(&_dac, value);
tushki7 0:60d829a0353a 68 }
tushki7 0:60d829a0353a 69
tushki7 0:60d829a0353a 70 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
tushki7 0:60d829a0353a 71 *
tushki7 0:60d829a0353a 72 * @param value 16-bit unsigned short representing the output voltage,
tushki7 0:60d829a0353a 73 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
tushki7 0:60d829a0353a 74 */
tushki7 0:60d829a0353a 75 void write_u16(unsigned short value) {
tushki7 0:60d829a0353a 76 analogout_write_u16(&_dac, value);
tushki7 0:60d829a0353a 77 }
tushki7 0:60d829a0353a 78
tushki7 0:60d829a0353a 79 /** Return the current output voltage setting, measured as a percentage (float)
tushki7 0:60d829a0353a 80 *
tushki7 0:60d829a0353a 81 * @returns
tushki7 0:60d829a0353a 82 * A floating-point value representing the current voltage being output on the pin,
tushki7 0:60d829a0353a 83 * measured as a percentage. The returned value will lie between
tushki7 0:60d829a0353a 84 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
tushki7 0:60d829a0353a 85 *
tushki7 0:60d829a0353a 86 * @note
tushki7 0:60d829a0353a 87 * This value may not match exactly the value set by a previous write().
tushki7 0:60d829a0353a 88 */
tushki7 0:60d829a0353a 89 float read() {
tushki7 0:60d829a0353a 90 return analogout_read(&_dac);
tushki7 0:60d829a0353a 91 }
tushki7 0:60d829a0353a 92
tushki7 0:60d829a0353a 93 #ifdef MBED_OPERATORS
tushki7 0:60d829a0353a 94 /** An operator shorthand for write()
tushki7 0:60d829a0353a 95 */
tushki7 0:60d829a0353a 96 AnalogOut& operator= (float percent) {
tushki7 0:60d829a0353a 97 write(percent);
tushki7 0:60d829a0353a 98 return *this;
tushki7 0:60d829a0353a 99 }
tushki7 0:60d829a0353a 100
tushki7 0:60d829a0353a 101 AnalogOut& operator= (AnalogOut& rhs) {
tushki7 0:60d829a0353a 102 write(rhs.read());
tushki7 0:60d829a0353a 103 return *this;
tushki7 0:60d829a0353a 104 }
tushki7 0:60d829a0353a 105
tushki7 0:60d829a0353a 106 /** An operator shorthand for read()
tushki7 0:60d829a0353a 107 */
tushki7 0:60d829a0353a 108 operator float() {
tushki7 0:60d829a0353a 109 return read();
tushki7 0:60d829a0353a 110 }
tushki7 0:60d829a0353a 111 #endif
tushki7 0:60d829a0353a 112
tushki7 0:60d829a0353a 113 protected:
tushki7 0:60d829a0353a 114 dac_t _dac;
tushki7 0:60d829a0353a 115 };
tushki7 0:60d829a0353a 116
tushki7 0:60d829a0353a 117 } // namespace mbed
tushki7 0:60d829a0353a 118
tushki7 0:60d829a0353a 119 #endif
tushki7 0:60d829a0353a 120
tushki7 0:60d829a0353a 121 #endif