|
|

楼主 |
发表于 2014-3-23 23:12:24
|
显示全部楼层
本帖最后由 lcokenm 于 2014-3-24 09:46 编辑
沧海笑1122 发表于 2014-3-23 12:38 
几点建议:
1、请将全部代码贴上来,看看你的初始化部分有问题没,或者定义是否有冲突。
2、我理解你是在 ... - //Declare: for the wireless setup terminal
- //1->initial devices
- //2->refresh OLED display
- //3->PIT setup catch the key input
- //4->send the user message from bluetooth
- //5->waiting for reciving the ach from the other bluetooth,if failed,resend
- //6->turn off the bluetooth
- //7->if key input from user,make sure the other bluetooth have turned on by user
- //8->reset
- //Includes!
- //Includes!
- //Includes!
- #include "SSD1306.h" //for OLED display
- #include <Event.h> //for PIT event
- #include <Timer.h> //for PIT event
- //Defines!
- //Defines!
- //Defines!
- //define user
- #define TURE 1
- #define FALSE 0
- //define UART speed
- #define bluetooth_btl 9600
- //difine OLED PINs
- #define OLED_CS 2
- #define OLED_D0 3
- #define OLED_D1 4
- #define OLED_RT 5
- #define OLED_DC 6
- SSD1306 oled(OLED_D1, OLED_D0, OLED_DC, OLED_RT, OLED_CS);
- //define display content
- #define display_content_column 0
- #define display_content_row 5
- #define display_page_0_column 0
- #define display_page_0_row 0
- #define display_page_1_column 0
- #define display_page_1_row 0
- //define PIT events
- Timer t;
- //define keyinput
- #define key_input_Pin 10 //
- #define key_input_refresh_time 150//ms
- int reset_order_by_user;
- //define system
- #define start_delay_time 2000
- #define initial_sensor_time 5000
- #define setup_success_delay_time 5000
- //define bluetooth static
- #define bluetooth_wait 0x00
- #define bluetooth_setup_success 0xF0
- #define bluetooth_setup_failed 0x0F
- #define bluetooth_setup_angle_okay 0x44
- #define bluetooth_setup_reset 0x33
- #define bluetooth_setup_reset_ack 0x55
- int bluetooth_receive = bluetooth_wait;
- //Functions!
- //Functions!
- //Functions!
- //Function:for OLED display a int num
- void OLED_Dis_int(int dis_int_num)
- {
- char a;
- a = dis_int_num / 100;
- oled.drawchar(display_content_column + 0, display_content_row, a + 48);
- a = dis_int_num % 100 /10;
- oled.drawchar(display_content_column + 6, display_content_row, a + 48);
- a = dis_int_num % 10;
- oled.drawchar(display_content_column +12, display_content_row, a + 48);
- }
- //Function:for catch a key input and return the key number
- void Function_key_input(void)
- {
- int key_in = digitalRead(key_input_Pin);
- if(key_in == 0)
- {
- reset_order_by_user = TURE;
- }
- }
- //Function:for HMI
- void Function_display_welcome_interface(void)
- {
- //for the first to setup
- //if(reset_order_by_user == FALSE){
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Welcome to use lgy's product!");
- oled.drawstring(display_page_0_column, display_page_0_row + 3, "Now I will tell how to use...");
- oled.drawstring(display_page_0_column, display_page_0_row + 5, "Press the key to continue...");
- oled.display();
- while(digitalRead(key_input_Pin) == 1);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "First,make sure the head-terminal have been turn on");
- oled.drawstring(display_page_0_column, display_page_0_row + 3, "Then put it on the table...");
- oled.drawstring(display_page_0_column, display_page_0_row + 6, "Please wait for 5 seconds...");
- oled.display();
- delay(initial_sensor_time);
- while(bluetooth_receive == bluetooth_wait) bluetooth_receive = Serial1.read();
- if(bluetooth_receive == bluetooth_setup_success){
- bluetooth_receive = bluetooth_wait;
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Congratuation!");
- oled.drawstring(display_page_0_column, display_page_0_row + 2, "The Terminal initial success!");
- oled.drawstring(display_page_0_column, display_page_0_row + 6, "Press the key to continue...");
- oled.display();
- while(digitalRead(key_input_Pin) == 1);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now put the head-terminal on your head");
- oled.drawstring(display_page_0_column, display_page_0_row + 4, "If finish,press the key to continue...");
- oled.display();
- while(digitalRead(key_input_Pin) == 1);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 2, "Now setup the warning angle");
- oled.display();
- delay(start_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Please adjust your head to set the angle");
- oled.drawstring(display_page_0_column, display_page_0_row + 3, "If okay,press the key and the warning angle will be saved!");
- oled.display();
- while(digitalRead(key_input_Pin) == 1);
- //bluetooth send the message to set the angle
- Serial1.println(bluetooth_setup_angle_okay);
- while(bluetooth_receive != bluetooth_setup_success){
- bluetooth_receive = Serial1.read();
- Serial1.println(bluetooth_setup_angle_okay);
- }
- bluetooth_receive = bluetooth_wait;
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now we have finished all the setup");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 1, "And enjoy yourself!");
- oled.drawstring(display_page_0_column, display_page_0_row + 3, "Thank you for choosing my product!");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 1, "For saving the power,the screen will be turned off few seconds later ");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 1, "If you want to reset the terminal,5 seconds later you can press the key to reset");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column + 20, display_page_0_row + 3, "Enjoy it!");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.display();
- }
- else{
- bluetooth_receive = 0;
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Sorry! initial failed! Turn off the power and retry again!");
- oled.display();
- }
- }
- //for reset the terminal
- /*
- else{
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now will reset the terminal...");
- oled.drawstring(display_page_0_column, display_page_0_row + 5, "Press the key to continue...");
- oled.display();
- while(digitalRead(key_input_Pin) == 1);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now please press the key on the head-terminal...");
- oled.display();
- while(bluetooth_receive != bluetooth_setup_reset){
- bluetooth_receive = Serial1.read();
- Serial1.println(bluetooth_setup_reset_ack);
- }
- bluetooth_receive = bluetooth_wait;
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Okay! Now will reset the warning angle");
- oled.display();
- delay(start_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Please adjust your head to set the angle");
- oled.drawstring(display_page_0_column, display_page_0_row + 3, "If okay,press the key and the warning angle will be saved!");
- oled.display();
- while(digitalRead(key_input_Pin) == 1);
- //bluetooth send the message to set the angle
- Serial1.println(bluetooth_setup_angle_okay);
- while(bluetooth_receive != bluetooth_setup_success){
- bluetooth_receive = Serial1.read();
- Serial1.println(bluetooth_setup_angle_okay);
- }
- bluetooth_receive = bluetooth_wait;
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 0, "Now we have finished all the setup again");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 1, "And enjoy yourself again!");
- oled.drawstring(display_page_0_column, display_page_0_row + 3, "Thank you for choosing my product!");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 1, "For saving the power,the screen will be turned off few seconds later");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column, display_page_0_row + 1, "If you want to reset the terminal,5 seconds later you can press the key to reset");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.drawstring(display_page_0_column + 20, display_page_0_row + 3, "Enjoy it! Thank you!");
- oled.display();
- delay(setup_success_delay_time);
- oled.clear();
- oled.display();
- }
- */
- }
- //Function:for initial each device
- void setup()
- {
- //for key_input_pin_mode
- pinMode(key_input_Pin,INPUT_PULLUP);
- //for initial UART for bluetooth
- Serial1.begin(bluetooth_btl);
- //while (!Serial1) ;
- //for initial OLED
- oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
- Function_display_welcome_interface();
- //for initial PIT events
- t.every(key_input_refresh_time, Function_key_input);
- }
- //Function:for main
- void loop()
- {
- //for refresh the OLED display content
- //oled.clear();
- //oled.drawstring(display_page_1_column + 0, display_page_1_row + 1, "Bluetooth for setup:");
- //oled.drawstring(display_page_1_column + 0, display_page_1_row + 3, "The Bot angle:");
- //oled.drawstring(display_page_1_column + 0, display_page_1_row + 4, "The Top angle:");
- //oled.drawstring(display_page_1_column +25, display_page_1_row + 7, " ---Design BY LGY");
- //oled.display();
- //for refresh the PIT events
- t.update();
- if(reset_order_by_user == TURE)
- {
- Function_display_welcome_interface();
- reset_order_by_user = FALSE;
- }
- }
复制代码 |
|