4 errors

Dependencies:   KS0108_PCF8574 mbed

Committer:
GuiTwo
Date:
Wed Sep 05 07:21:59 2012 +0000
Revision:
0:936f1c020120
Child:
1:4f46d81502aa
With KS0108;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GuiTwo 0:936f1c020120 1 #include "mbed.h"
GuiTwo 0:936f1c020120 2 #include "menbed.h"
GuiTwo 0:936f1c020120 3 //#include "PCF8574_DataBus.h"
GuiTwo 0:936f1c020120 4 //#include "KS0108.h"
GuiTwo 0:936f1c020120 5
GuiTwo 0:936f1c020120 6
GuiTwo 0:936f1c020120 7 AnalogIn photocell(p15);
GuiTwo 0:936f1c020120 8 PwmOut led1(LED1);
GuiTwo 0:936f1c020120 9 PwmOut led2(LED2);
GuiTwo 0:936f1c020120 10 DigitalOut led3(LED3);
GuiTwo 0:936f1c020120 11 DigitalOut led4(LED4);
GuiTwo 0:936f1c020120 12
GuiTwo 0:936f1c020120 13 //I2C Bus
GuiTwo 0:936f1c020120 14 //I2C i2c(p9, p10);
GuiTwo 0:936f1c020120 15
GuiTwo 0:936f1c020120 16 //PCF8574_DataBus DB = PCF8574_DataBus(i2c, 0x40); //Copy constructors..
GuiTwo 0:936f1c020120 17
GuiTwo 0:936f1c020120 18
GuiTwo 0:936f1c020120 19
GuiTwo 0:936f1c020120 20
GuiTwo 0:936f1c020120 21
GuiTwo 0:936f1c020120 22 float photocellVoltage(void) {return 3.3 * photocell;}
GuiTwo 0:936f1c020120 23 void setLed1Pwm (float d) {led1 = d / 100.0;}
GuiTwo 0:936f1c020120 24 float getLed1Pwm (void) {return led1 * 100.0;}
GuiTwo 0:936f1c020120 25 void setLed2Pwm (float d) {led2 = d / 100.0;}
GuiTwo 0:936f1c020120 26 float getLed2Pwm (void) {return led2 * 100.0;}
GuiTwo 0:936f1c020120 27 void toggleLed3 () {led3 = led3 ^ 1;}
GuiTwo 0:936f1c020120 28 void lightLed4 () {led4 = 1;}
GuiTwo 0:936f1c020120 29 void extinguishLed4 () {led4 = 0;}
GuiTwo 0:936f1c020120 30
GuiTwo 0:936f1c020120 31 int main() {
GuiTwo 0:936f1c020120 32
GuiTwo 0:936f1c020120 33 // Declare all the submenus so that they can be referenced in the
GuiTwo 0:936f1c020120 34 // definitions of other menus
GuiTwo 0:936f1c020120 35 MenbedMenu *rootMenu;
GuiTwo 0:936f1c020120 36 MenbedMenu *measurementMenu;
GuiTwo 0:936f1c020120 37 MenbedMenu *controlMenu;
GuiTwo 0:936f1c020120 38 MenbedMenu *aboutMenu;
GuiTwo 0:936f1c020120 39
GuiTwo 0:936f1c020120 40 // Root menu--to create a menu, we first create an array of pointers to
GuiTwo 0:936f1c020120 41 // all the menu items that will populate the menu. The MenbedMenuItem
GuiTwo 0:936f1c020120 42 // constructor take five arguments: the function to be executed when the
GuiTwo 0:936f1c020120 43 // item is selected; the child menu to open when the item is selected;
GuiTwo 0:936f1c020120 44 // a boolean indicating whether the child menu is actually this menu's
GuiTwo 0:936f1c020120 45 // ancestor, (useful when creating "go to root menu" items); a parameter
GuiTwo 0:936f1c020120 46 // object that holds a value to be viewed or modified; and a text string
GuiTwo 0:936f1c020120 47 // indicating what the menu item should say. The text string may contain
GuiTwo 0:936f1c020120 48 // a printf-style specifier for a float that is bracketed by \t characters
GuiTwo 0:936f1c020120 49 // to offset it from the surrounding text. If the float specified is
GuiTwo 0:936f1c020120 50 // found, it will be replaced by the value of the parameter.
GuiTwo 0:936f1c020120 51 MenbedMenuItem *rootMenuItems[3] = {
GuiTwo 0:936f1c020120 52 new MenbedMenuItem (NULL, &measurementMenu, false, NULL, "Measurements"),
GuiTwo 0:936f1c020120 53 new MenbedMenuItem (NULL, &controlMenu, false, NULL, "Controls"),
GuiTwo 0:936f1c020120 54 new MenbedMenuItem (NULL, &aboutMenu, false, NULL, "About"),
GuiTwo 0:936f1c020120 55 };
GuiTwo 0:936f1c020120 56 // After we have the array of pointers to menu items, we pass the number of
GuiTwo 0:936f1c020120 57 // elements in the arry and the array itself to the MenbedMenu constructor.
GuiTwo 0:936f1c020120 58 rootMenu = new MenbedMenu (3, rootMenuItems);
GuiTwo 0:936f1c020120 59
GuiTwo 0:936f1c020120 60 // Measurements menu--the first item of the measurement menu displays the
GuiTwo 0:936f1c020120 61 // voltage and the resistor divider junction formed between a photocell and
GuiTwo 0:936f1c020120 62 // a fixed resistor. To print this voltage as part of a menu item, we
GuiTwo 0:936f1c020120 63 // create a MenbedMenuParam object that takes as arguments to its
GuiTwo 0:936f1c020120 64 // constructor: a pointer to a function that returns a float containing the
GuiTwo 0:936f1c020120 65 // value of the parameter; a pointer to a function that we would call to
GuiTwo 0:936f1c020120 66 // change the value of the parameter; a boolean (irrevelant here)
GuiTwo 0:936f1c020120 67 // indicating whether the parameter, if it were modifiable by the user,
GuiTwo 0:936f1c020120 68 // should be updated as the user is changing its value or whether its
GuiTwo 0:936f1c020120 69 // should only be updated after the user has confirmed the new value; a
GuiTwo 0:936f1c020120 70 // minimum value for the parameter; a maximum value; and a step size.
GuiTwo 0:936f1c020120 71 MenbedMenuParam photocellParam (photocellVoltage, NULL, false, 0.0, 0.0, 0.0);
GuiTwo 0:936f1c020120 72 // Having created the parameter, we pass it as the 4th argument of the
GuiTwo 0:936f1c020120 73 // MenbedMenuItem constructor. Note the \t-offset %.2f format specified
GuiTwo 0:936f1c020120 74 // in the menu item text. The menu system will call the photocellVoltage
GuiTwo 0:936f1c020120 75 // function specified in the parameter constructor above and then print the
GuiTwo 0:936f1c020120 76 // float that it returns in place of the %.2f in the menu text.
GuiTwo 0:936f1c020120 77 MenbedMenuItem *measurementMenuItems[2] = {
GuiTwo 0:936f1c020120 78 new MenbedMenuItem (NULL, NULL, false, &photocellParam, "Photocell: \t%.2f\tV"),
GuiTwo 0:936f1c020120 79 new MenbedMenuItem (NULL, &rootMenu, true, NULL, "Home") };
GuiTwo 0:936f1c020120 80 measurementMenu = new MenbedMenu (2, measurementMenuItems);
GuiTwo 0:936f1c020120 81
GuiTwo 0:936f1c020120 82 // Controls menu--We have modifiable parameters in the first and second
GuiTwo 0:936f1c020120 83 // meu items of the controls menu. Walking through the first parameter
GuiTwo 0:936f1c020120 84 // constructor, the getLed1Pwm function pointer points to a function that
GuiTwo 0:936f1c020120 85 // returns the current value of the PWM duty cycle. The setLed1Pwm
GuiTwo 0:936f1c020120 86 // function pointer points to a function which sets the PWM duty cycle.
GuiTwo 0:936f1c020120 87 // The boolean set to true indicates that as soon as the user makes a
GuiTwo 0:936f1c020120 88 // change to the parameter, the setLed1Pwm function will be called. The
GuiTwo 0:936f1c020120 89 // menu system will not wait for the user to confirm his change before
GuiTwo 0:936f1c020120 90 // making the call. The 0.0 and 100.0 represent the minimum and
GuiTwo 0:936f1c020120 91 // maximum PWM values. The final 1.0 paramter is the step size when
GuiTwo 0:936f1c020120 92 // changing the PWM duty cycle.
GuiTwo 0:936f1c020120 93 MenbedMenuParam pwmParam1 (getLed1Pwm, setLed1Pwm, true, 0.0, 100.0, 1.0);
GuiTwo 0:936f1c020120 94 // The only different in this parameter from the one above is that the PWM
GuiTwo 0:936f1c020120 95 // duty cycle is not updated (setLed2Pwm is not called) until the user
GuiTwo 0:936f1c020120 96 // confirms the new duty cycle. If the user cancels his modifications
GuiTwo 0:936f1c020120 97 // (either by pushing the cancel button or pushing and holding the select
GuiTwo 0:936f1c020120 98 // button) setLed2PWM is never called.
GuiTwo 0:936f1c020120 99 MenbedMenuParam pwmParam2 (getLed2Pwm, setLed2Pwm, false, 0.0, 100.0, 1.0);
GuiTwo 0:936f1c020120 100 // The third, fourth, and fifth items of the control menu demonstrate
GuiTwo 0:936f1c020120 101 // functions when a menu item is selected. The ability to call a function
GuiTwo 0:936f1c020120 102 // can be combined with either displaying a submenu or editing a parameter.
GuiTwo 0:936f1c020120 103 MenbedMenuItem *controlMenuItems[6] = {
GuiTwo 0:936f1c020120 104 new MenbedMenuItem (NULL, NULL, false, &pwmParam1, "LED1 PWM: \t%.0f\t%"),
GuiTwo 0:936f1c020120 105 new MenbedMenuItem (NULL, NULL, false, &pwmParam2, "LED2 PWM: \t%.0f\t%"),
GuiTwo 0:936f1c020120 106 new MenbedMenuItem (toggleLed3, NULL, false, NULL, "Toggle LED3"),
GuiTwo 0:936f1c020120 107 new MenbedMenuItem (lightLed4, NULL, false, NULL, "Light LED4"),
GuiTwo 0:936f1c020120 108 new MenbedMenuItem (extinguishLed4, NULL, false, NULL, "Extinguish LED4"),
GuiTwo 0:936f1c020120 109 new MenbedMenuItem (NULL, &rootMenu, true, NULL, "Home") };
GuiTwo 0:936f1c020120 110 controlMenu = new MenbedMenu (6, controlMenuItems);
GuiTwo 0:936f1c020120 111
GuiTwo 0:936f1c020120 112 // About menu--there's nothing fancy here, but the lack of a "Home" item
GuiTwo 0:936f1c020120 113 // forces the user to employ the cancel button, either directly or by
GuiTwo 0:936f1c020120 114 // pushing and hold the select button, to return to the root menu.
GuiTwo 0:936f1c020120 115 MenbedMenuItem *aboutMenuItems[3] = {
GuiTwo 0:936f1c020120 116 new MenbedMenuItem (NULL, NULL, false, NULL, " NXP3915"),
GuiTwo 0:936f1c020120 117 new MenbedMenuItem (NULL, NULL, false, NULL, " Copyright 2011"),
GuiTwo 0:936f1c020120 118 new MenbedMenuItem (NULL, NULL, false, NULL, " xxxxxxxx@xxx.xxx") };
GuiTwo 0:936f1c020120 119 aboutMenu = new MenbedMenu (3, aboutMenuItems);
GuiTwo 0:936f1c020120 120
GuiTwo 0:936f1c020120 121 // Having created the menus, menu items, and item parameters, we are ready
GuiTwo 0:936f1c020120 122 // to instantiate the display. MenbedDisplayHD44780 extends MenbedDisplay
GuiTwo 0:936f1c020120 123 // and implements the all-important writeLine function allong with some
GuiTwo 0:936f1c020120 124 // other less important functions. The pins we pass to the constructor
GuiTwo 0:936f1c020120 125 // specify the physical interface connection to the LCD.
GuiTwo 0:936f1c020120 126 MenbedDisplayHD44780 *hd44780Lcd = new MenbedDisplayHD44780
GuiTwo 0:936f1c020120 127 (p25, p26, p27, p28, p29, p30, MenbedDisplayHD44780::LCD20x4);
GuiTwo 0:936f1c020120 128
GuiTwo 0:936f1c020120 129 /* KS0108 *LCD = new KS0108(
GuiTwo 0:936f1c020120 130 p21,//_RST
GuiTwo 0:936f1c020120 131 p5,//_DI
GuiTwo 0:936f1c020120 132 p30,//_RW
GuiTwo 0:936f1c020120 133 p29,//_E
GuiTwo 0:936f1c020120 134 p25,//_CS2
GuiTwo 0:936f1c020120 135 p6,//_CS1
GuiTwo 0:936f1c020120 136 DB
GuiTwo 0:936f1c020120 137 );
GuiTwo 0:936f1c020120 138 */
GuiTwo 0:936f1c020120 139
GuiTwo 0:936f1c020120 140
GuiTwo 0:936f1c020120 141 // Now, we have the menu objects and the display object. All we have to do
GuiTwo 0:936f1c020120 142 // is create the menbed menu system. The number of buttons used by the
GuiTwo 0:936f1c020120 143 // menu system is specified by the number of pins passed to the Menbed
GuiTwo 0:936f1c020120 144 // constructor. The pin order is select, down, up, cancel. With
GuiTwo 0:936f1c020120 145 // constructor overloading, we can opt out of using the cancel and up
GuiTwo 0:936f1c020120 146 // buttons.
GuiTwo 0:936f1c020120 147
GuiTwo 0:936f1c020120 148 /* Four buttons (select, down, up, cancel ) */
GuiTwo 0:936f1c020120 149 //Menbed menbed(p8, p11, p12, p13,&rootMenu,hd44780Lcd);
GuiTwo 0:936f1c020120 150
GuiTwo 0:936f1c020120 151
GuiTwo 0:936f1c020120 152 /* Three buttons (select, down, up) */
GuiTwo 0:936f1c020120 153
GuiTwo 0:936f1c020120 154 Menbed menbed(p22, p24, p23,
GuiTwo 0:936f1c020120 155 &rootMenu,
GuiTwo 0:936f1c020120 156 hd44780Lcd);
GuiTwo 0:936f1c020120 157
GuiTwo 0:936f1c020120 158
GuiTwo 0:936f1c020120 159 /* Two buttons (select, down) */
GuiTwo 0:936f1c020120 160 /*
GuiTwo 0:936f1c020120 161 Menbed menbed(p22, p24,
GuiTwo 0:936f1c020120 162 &rootMenu,
GuiTwo 0:936f1c020120 163 hd44780Lcd);
GuiTwo 0:936f1c020120 164 */
GuiTwo 0:936f1c020120 165
GuiTwo 0:936f1c020120 166 // The menu system runs in the background using Ticker objects. The user
GuiTwo 0:936f1c020120 167 // can now run whatever application code he pleases.
GuiTwo 0:936f1c020120 168 while(1) {}
GuiTwo 0:936f1c020120 169 }