Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 201_test-UI 200_yotsuba_21
Diff: ui.cpp
- Revision:
- 1:ed6249618fd3
- Parent:
- 0:2623196cd444
- Child:
- 2:a5e8e6156172
--- a/ui.cpp Tue Jan 19 09:24:37 2021 +0000
+++ b/ui.cpp Wed Mar 03 11:49:25 2021 +0000
@@ -1,40 +1,100 @@
#include "ui.h"
UI::UI()
-: lcd(lcd_SDA, lcd_SCL),
- b0(button0_pin),
- b1(button1_pin),
- b2(button2_pin)/*,
- UIthread.start(callback(this,&UI::button))
- */
+: lcd(PB_9, PB_8),
+ b0_(PC_3),
+ tgl1(PA_9),
+ tgl2(PB_10),
+ tgl3(PB_5),
+ buzz(PC_7)
{
- team = 0;//初期化
+ team = 0;//初期化
algorithm = 0;
displayst = 0;
+ mode = 0;
+ name1 = name2 = NULL;
+ for (int i = 0; i < 4; i++) b[i] = b_[i] = 0;
+ UIthread.start(callback(this,&UI::display));
+}
+
+void UI::updatebt()
+{
+ b0 = b0_ * 100;
+ for(int i = 0; i < 4; i++){
+ if((b0 > 10*(2*i + 3)) && (b0 < 10*(2*i + 5))) b[i] = 1;
+ else b[i] = 0;
+ }
+ if(b[0] && (!b_[0])){
+ team = !team;
+ buzz.beep(1760.0,0.2);
+ }
+ if(b[1] && (!b_[1])){
+ ++algorithm %= 5;
+ buzz.beep(1760.0,0.4);
+ }
+ if(b[2] && (!b_[2])){
+ ++displayst %= 4;
+ buzz.beep(1760.0,0.6);
+ }
+ if(b[3] && (!b_[3])){
+ start = !start;
+ buzz.beep(1760.0,0.6);
+ }
+ for(int i = 0; i < 4; i++) b_[i] = b[i];
+ mode = (4*!tgl1)+(2*!tgl2)+(!tgl3);
}
-void UI::button()
+void UI::change(char *valname1_, char *valname2_, double *dispvalue_)
{
- //タクトスイッチver ディップやトグルだと変わってくる
- //% の後は各状態の数
- if(b0.read() && (!b0_)) team = ++team % 2;
- if(b1.read() && (!b1_)) algorithm = ++algorithm % 4;
- if(b2.read() %% (!b2_)) displayst = ++displayst % 4;
+ name1 = valname1_;
+ name2 = valname2_;
+ dispvalue[0] = dispvalue_[0];
+ dispvalue[1] = dispvalue_[1];
}
-void UI::display(char valname1, char valname2, double* dispvalue)
+//void UI::display(char *valname1, char *valname2, double *dispvalue)
+void UI::display()
{
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print(this.team)//team
- lcd.setCursor(0,1);
- lcd.print(this.algorithm);//algo
- lcd.setCursor(1,0);
- lcd.print(valname1);//
- lcd.setCursor(1,1);
- lcd.print(valname2);//
- lcd.setCursor(5,0);
- lcd.print(dispvalue++);
- lcd.setCursor(5,1);
- lcd.print(dispvalue);
+ while(1) {
+ updatebt();
+ ThisThread::sleep_for(10ms);
+ lcd.clear();
+
+ lcd.setCursor(0,0);
+ lcd.print(algorithm);//algo
+
+ lcd.setCursor(0,0);
+ lcd.print(algorithm);//algo
+ lcd.setCursor(1,0);
+ lcd.print(displayst);
+ lcd.setCursor(2,0);
+ lcd.print(name1);//
+ lcd.setCursor(5,0);
+ lcd.print(dispvalue[0]);
+ /*
+ lcd.print(b[0]);
+ lcd.setCursor(6,0);
+ lcd.print(b[1]);
+ lcd.setCursor(7,0);
+ lcd.print(b[2]);
+ */
+ lcd.setCursor(0,1);
+ lcd.print(team);//team
+ lcd.setCursor(1,1);
+ lcd.print(mode);
+ lcd.setCursor(2,1);
+ lcd.print(name2);//
+ lcd.setCursor(5,1);
+ lcd.print(dispvalue[1]);
+// lcd.print(b0);
+ ThisThread::sleep_for(40);
+ }
+}
+
+void UI::returnchar(char *buf)
+{
+ for(int i = 0; i < 4; i++)
+ {
+ buf[i] = name1[i];
+ }
}
\ No newline at end of file