5 years, 11 months ago.

why does it not do anything? Should I do something like while loop but what should I write in it?

  1. include "mbed.h"
  2. include "C12832.h"

class currenttime { private: int hours,minutes,seconds; Ticker updatetime; public: currenttime(int s, int m, int h): seconds (s), minutes (m), hours(h){updatetime.attach(callback(this,&currenttime::nowtime),0.5);} void nowtime (void){ seconds++; if (seconds == 60) {seconds =0; minutes++;}

if (minutes == 60) {minutes =0; hours++;}

if (hours ==24) {hours =1;}

} int goget_seconds(void){return seconds;} int goget_minutes(void){return minutes;} int goget_hours(void){return hours;} };

class Pot { private: AnalogIn b; interface to configure input public: Pot(PinName both) : b(both){} float turnpot (void) {return b.read();} };

class nextpage { private: currenttime *watch; C12832 lcd; int set_min, set_sec; Pot *left; Pot *right; InterruptIn fire, up,down;

public: nextpage (currenttime *t,Pot *pot1, Pot *pot2, PinName a, PinName b, PinName c, PinName d, PinName e, PinName f,PinName u, PinName bwh): {watch(t), left(pot1),right(pot2),lcd (a,b,c,d,e), fire(f), up(u), down(bwh)) { fire.rise(callback(this, &nextpage::setup)); up.rise(callback(this, &nextpage::currentpage)); down.rise (callback(this, &nextpage::clear));}

void clear (void) {lcd.cls();}

void setup(){ lcd.locate (0,18); lcd.printf ("set time %f:%f",set_sec, set_min); set_sec = left-> turnpot()*(float)60; set_min = right-> turnpot()*(float)60;}

void currentpage(void){ lcd.locate (0,18); lcd.printf ("page 1: time now is %d:%d",watch->goget_minutes(), watch->goget_seconds() );} };

int main() { currenttime *x= new currenttime (0,0,0); Pot *y = new Pot(A0); Pot *z = new Pot(A1); nextpage n(x,y,z, D11, D13, D12, D7, D10, D4, A2);

}

1 Answer

5 years, 11 months ago.

Two things.

1: when positing code please do

<<code>>
your code
<</code>>

so that the formatting is readable.

2: Yes, you need a loop. Your code sets things up and then exits.

Since it looks like all of your controls are interrupts so all you should need is something like:

int main() {
    currenttime *x= new currenttime (0,0,0); 
    Pot *y = new Pot(A0); 
    Pot *z = new Pot(A1);
    nextpage n(x,y,z, D11, D13, D12, D7, D10, D4, A2);
    while (true) {
      wait(1);
    }
}

And for future reference, variable names of x,y,z,u,f etc... don't make for good code. Use longer meaningful names for them, it makes for far more maintainable code in the long run.