Skip to main content

Posts

Showing posts with the label arrays

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...

Day 8: Intro to Data Structures | Servos and More Music

Lecture One Dimensional Arrays Arrays are a type of data structure that allows for working with a group of values using a single identifier.  Lab Servos Servos rotate to a particular angular position and stay there until told to move to a new position.  There are both standard and continuous rotation servos. Unmodified ones have a fixed range due to a potentiometer in line with the drive shaft that is used for reporting the present position. Servos are controlled by sending a pulse of a certain length; this length determines the position it will rotate to. However, in a continuous rotation servo, there is no potentiometer and the servo rotates continuously, and the pulse length determines the speed instead.  Servos draw a significant amount of current, typically more than an Arduino can supply, so it is best to use a separate power supply. Homework Hardware //Servo Potentiometer Control #include <Servo.h> const int SERVO=9; //Servo on...