/* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //Create strings of text to output to the user char * requiredMsg = "ECE382 is my favorite class! "; char * prompt = "Message?"; char * promptKey = "Press123"; char * message1 = "Learn from yesterday... "; char * message2 = "Live for today... "; char * message3 = "Hope for tomorrow. "; //SPI initialization function initSPI(); // LCD initialization function LCDinit(); //Clear the LCD screen LCDclr(); //Position the cursor to write the prompt to the user. cursorToLineOne(); writeString(prompt); cursorToLineTwo(); writeString(promptKey); int buttonPushed = 0; //A different value is returned depending on which button is pushed. buttonPushed = pollButton(); //Move the selected message to the screen if (buttonPushed == 1) { scrollString(requiredMsg, message1); } if (buttonPushed == 2) { scrollString(requiredMsg, message2); } if (buttonPushed == 3) { scrollString(requiredMsg, message3); } return 0; }
void loop() { long unsigned int current_time = millis(); if(current_time >= sample_clock){ // reset sampling clock sample_clock += SAMPLE_PERIOD; // poll the potentiometer once each sample period // poll_potentiometer(); // dim the LED string using potentiometer as a reference // analogWrite(LED_PWM_PIN, map(dimmer_cts, 0, 1025, 0, 255)); // step through impulse routine // step_pulser(current_time, &pulser); // poll the tachometer encoder //poll_encoder(current_time, &tach_enc); if (pollButton(&button) >= shortPress){ backlight_clock = current_time + backlight_period; } if(current_time >= update_tach_clock){ update_tach_clock = current_time + update_tach_period; // check if tachometer interrupt has been fired if(tach_enc.pin_state){ tach_enc.pin_state = 0; tach_enc.last_period = (current_time - tach_enc.startTime); tach_enc.startTime = current_time; } digitalWrite(LED_PIN, digitalRead(tach_enc.pin_num)); } if(current_time >= calc_tach_clock){ calc_tach_clock = current_time + calc_tach_period; calculate_tach(current_time, &tach_enc); } if(current_time >= calc_current_clock){ calc_current_clock = current_time + calc_current_period; calculate_current(¤t_sensor); calculate_voltage(&volt_sensor); } // if(current_time >= blink_clock){ // led_state = !led_state; // digitalWrite(LED_PIN, led_state); // blink_clock = current_time + blink_period; // } if(current_time >= toggle_display_clock){ toggle_display_clock = current_time + toggle_display_period; toggle_display = !toggle_display; gotoXY(0,2); if(toggle_display == SHOW_RPM) LcdString((char*)"Speed:"); else if(toggle_display == SHOW_WATTS) LcdString((char*)"Power:"); } if(current_time >= update_display_clock){ update_display_clock = current_time + update_display_period; snprintf(outputbuffer, 11,"%d.%02d Amps", (current_sensor.current)/1000, ((abs(current_sensor.current) % 1000) / 10)); gotoXY(6,1); LcdString((char*)" "); gotoXY(6,1); LcdString(outputbuffer); if(toggle_display == SHOW_RPM){ snprintf(outputbuffer,11,"%ld.%01ld RPM", (60*tach_enc.hertz)/1000, ((60*tach_enc.hertz)%1000) / 100); } else if(toggle_display == SHOW_WATTS){ watts = abs(current_sensor.current * volt_sensor.voltage) / 1000; snprintf(outputbuffer,11,"%ld.%01ld Watts", watts/1000, (watts%1000) / 100); } gotoXY(6,3); LcdString((char*)" "); gotoXY(6,3); LcdString(outputbuffer); snprintf(outputbuffer,12,"%ld.%02ld Volts", volt_sensor.voltage/1000, ((volt_sensor.voltage)%1000) / 10); gotoXY(6,5); LcdString((char*)" "); gotoXY(6,5); LcdString(outputbuffer); } // if(current_time >= post_to_serial_clock){ // post_to_serial_clock = current_time + post_to_serial_period; //// Serial.write("<r>"); //// Serial.write(tach_enc.hertz / 1000); //// Serial.write("."); //// Serial.write(tach_enc.hertz % 1000); // sprintf(outputbuffer, "<r>%lu.%03lu\t%ld.%03ld\t%d\t%ld\t%ld.%03ld\t%ld</r>\n", current_time/1000, // current_time % 1000, (60*tach_enc.hertz)/1000, ((60*tach_enc.hertz) % 1000)/10,current_sensor.current, current_sensor.sense_cts, // volt_sensor.voltage / 1000, volt_sensor.voltage % 1000, volt_sensor.sense_cts); // Serial.write(outputbuffer); // } if(current_time <= backlight_clock){ analogWrite(BACKLIGHT_PIN, 35); } else analogWrite(BACKLIGHT_PIN, 0); } }