Skip to main content

Posts

Showing posts from October, 2017

Day 13: 2-Dimensional Arrays || I2C Sensors

Lab: I2C Temperature Sensor Figure 1.1 Serial monitor displaying temperature data Code //Reads Temp from I2C temperature sensor and prints it on the serial port //Include Wire I2C library #include <Wire.h> int temp_address = 72; //1001000 written as decimal number void setup() {  //Start serial communication at 9600 baud  Serial.begin(9600);  //Create a Wire object  Wire.begin(); } void loop() {  //Send a request  //Start talking to the device at the specified address  Wire.beginTransmission(temp_address);  //Send a bit asking for register zero, the data register  Wire.write(0);  //Complete Transmission  Wire.endTransmission();  //Read the temperature from the device  //Request 1 Byte from the specified address  Wire.requestFrom(temp_address, 1);  //Wait for response  while(Wire.available() == 0);  //Get the temp and read it into a vari...

Day 12: Data Files | LCD Displays

Lab LCD Displays LCD displays can display values on the screen, and also allow someone to interact with it by pressing buttons on it. 1023 Select: 740-741 Left: 503 Down: 326-327 Up: 142-143 Right: 0 Lecture Data Files I/O Statements Must use pointers to reference file pointer defined with FILE declaration as in FILE *sensor1; Asterisk before identifier specifies that identifier is a pointer sensor=fopen("sensor1.txt","r"); fopen function optains info needed to assign file pointer for specific file.  R is for read, w is for write Homework Hardware //LCD with Progress Bar //Include the library code: #include <LiquidCrystal.h> //Initialize the library with the numbers of the interface pins LiquidCrystal lcd(8,9,4,5,6,7); //Create the progress bar characters byte p20[8] = {  B10000,  B10000,  B10000,  B10000,  B10000,  B10000,  B10000,  B10000, }; byte p40[8] = { ...

Day 11: Statistics, Sorting, and Searching

Sorting Selection sort Homework Cipher Code in action Code for Cipher.h #ifndef _CIPHERH_ #define _CIPHERH_ #include <stdio.h> #include <string.h> #include <stdlib.h> char *getInput(void) {   int mem=16;    char *message=malloc(mem); //Preallocate memory   printf("Input Message\n"); fgets(message,mem,stdin); //Take user input  while(message[strlen(message)-1]!='\n') //Check if there's still space { mem*=2;  message=realloc(message,mem); //Double amount of space fgets(message + mem/2 - 1, mem/2 + 1, stdin); //Read the rest of the line } return message; //return character array message } int EncryptMessage(void) {   char *message=getInput(); //call getInput function   int ch; //initialize variable ch      int shift; //initialize variable shift      printf("\nInput number of characters to shift: \n");   scanf("%i",&shift); //ask user t...