v1
Revision 1:4715a1559604, committed 2019-11-20
- Comitter:
- OJ_2k
- Date:
- Wed Nov 20 14:34:37 2019 +0000
- Parent:
- 0:84b27625b7d0
- Commit message:
- v1
Changed in this revision
| lab10.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/lab10.cpp Wed Nov 13 16:42:15 2019 +0000
+++ b/lab10.cpp Wed Nov 20 14:34:37 2019 +0000
@@ -6,6 +6,22 @@
char scan4by3keypad(BusIn* col, BusOut* row, const char k[4][3]); //function prototype for the scan4by3keypad function(returns a char)
TextLCD lcd(D6, D5, D4, D3, D2, A0); // creates a global object of the TextLCD class called lcd with the pins D6,D5,D4,D3,D2,A0 assigned. These pins correspond to the pins rs, e, d4-d7 on the lcd
char usercode[4] = {' ',' ',' ',' '};//creates a global char array that is used to store the entered code. This array is initialized to nothing
+
+
+char const MGPIOB=0x13;
+char const MOLATB=0x15; //modified
+char const MIODIRB=0x01;
+char const MGPPUB=0x0D;
+char const MGPIOA=0x12;
+char const MOLATA=0x14;
+char const MIODIRA=0x00;
+char const MGPPUA=0x0C;
+
+char const initWriteByte = 0b01000000;
+char const initReadByte = 0b01000001;
+
+
+
/************************************************************************************
Main function:
Purpose: The purpose of the main function is to determine the usercode entered from the keypad. If the code is correct the function will light the green
@@ -35,15 +51,21 @@
readtempurature(&temp): A function created by Ben that returns a value of type float representing the temperature. This function accepts the address of the temp pins.
*************************************************************************************/
int main() {
- AnalogIn temp (A1);//indentifies the pin A1 as an analogin pin named temp
- BusOut rowpins(D13,D12,D11,D10);//busout for my row pins
+ SPI spi(PC_12,PC_11,PC_10); //mosi, miso, sclk
+ DigitalOut cs(A5);
+ AnalogIn temp (A1);//indentifies the pin A1 as an analogin pin named temp
+ BusOut rowpins(D13,D12,D11,D10);//busout for my row pins
BusIn columnpins(D9,D8,D7);//busin for my colummn pins
columnpins.mode(PullDown);//enables the internal pulldown for the column pins
const char button[4][3]= {{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'4','0','#'}};//array which helps determine which button was
-bool access = false;//boolean variable that will change depending on whether the keycode is correct or incorrect.
+ bool access = false;//boolean variable that will change depending on whether the keycode is correct or incorrect.
+
+ spi.format(8,0); //set spi to transfer 8 bits with SPI MODE 0 (0,0)
+ spi.frequency(1000000); //set spi clock to 1MHz
+
while(access == false)//loops through this code while the access is false (keycode entered is wrong)
{
lcd.cls();//clears the LCD display
@@ -87,8 +109,25 @@
}
for(;;)//infinite loop
{
+ float tempurature;
+ float y;//float value that stores the duty-cyle calculated on line 15
+ int bite;
+ tempurature=readtempurature(&temp); //calls the temperature function and stores its return value
+ y = (((0.25*tempurature) + 3)/100); //formula that converts the temperature measured by the thermistor into an equivalent duty-cycle, in order for the servo to display an accurate 1:1 scale, change the constant from 0.3 to 0.05
+ //servo.period(0.02); // sets the period of the servo PWM to 20 ms as specifed in lesson 7
+ //servo.write(y); //writes the calculated duty-cycle to the servo
+ bite=((28.333333333333*(y*100))-85);
+ //printf("The tempurature is: %f\n",tempurature);//prints the temperature in celcius to the serial terminal
+ //wait(0.5); //waits for half a second before running the next iteration
+ cs = 0;
+ spi.write(bite); //writes the calculated duty-cycle to the servo
+ printf("Bite = %.2f", bite);
+ wait(0.5);
+ cs = 1;
+ //printf("The tempurature is: %f\n",temperature);//prints the temperature in celcius to the serial terminal
+ //wait(0.5); //waits for half a second before running the next iteration
lcd.locate(0,1);//moves the cursor to the 0th column of the first row on the LCD
- lcd.printf("Temp: %.2f",readtempurature(&temp));//prints the value returns by the readtempurature function.(.2f will cutoff the value after the second decimal place.
+ lcd.printf("Temp: %.2f",tempurature);//prints the value returns by the readtempurature function.(.2f will cutoff the value after the second decimal place.
wait(1.5);//waits 1.5 seconds as to no make the display look all glitchy.
}
}