Posts

Day 23 Nov 16

Image
For homework we had to create a code that could measure which way the wind was blowing. This code prints the percent of wind blowing in each direction, This is the screenshot for the first question. It  prints out the percentage of wind in each direction This is the code for problems 2 and 3, it prints out each direction if they have the same amount of values in the grid, and it also prints out  and it also prints out if there's a possible change of a cyclone if every direction has a value more than zero Here's a screenshot of problem 4 creating a grid of symbols 

Day 22 Nov 14

Image
For homework we had to modify the hand recognition code to read the knowns from a data file, create an array of unknowns from user input, point to the known value with the smallest difference, and print it all out. Here's the code #include <iostream> #include <cmath> #include <fstream> //#define FILENAME "known.txt" using namespace std; int main(void) { double known[5]; ifstream myfile ("known.txt");   if (myfile.is_open())   {     int k;     for(k=0;k<=4;k++) { myfile>>known[k]; }     myfile.close();   } //Declare and initialize variables. //double unknown[5]={5.4,7.2,7.9,7.4,5.1}; double unknown[5]; //double known[5]={6.2,7.0,8.0,7.4,5.8}; cout<<"enter 5 unknown values"<<endl; int k; for(k=0;k<=4;k++) { cin>>unknown[k]; } double distance(double hand_1[5],double hand_2[5]); double comp(double hand_1[5],double hand_2[5]); // Compute and print ...

Day 21 Nov 9

Image
For the homework I had to create a quick sort function, and then use a quicksort function in a linked list. Here's a screenshot of both parts of the homework: Just the quick list part #include <stdio.h> #include <stdlib.h> //void quicksort(int[], int, int); //int partition( int[], int, int); int partition(int a[], int p, int r) { int i,j, pivot, temp; pivot = a[p]; i = p; j = r; while(1) { while(a[i] < pivot && a[i] != pivot) i++; while(a[j] > pivot && a[j] != pivot) j--; if (i <j) { temp = a[i]; a[i] = a[j]; a[j] = temp; } else { return j; } } } void quicksort(int a[], int p, int r) { if (p < r) { int q; q = partition(a, p ,r); quicksort(a,p,q); quicksort(a, q+1, r); } } int main(void) { struct sort; int a[]= {25, 52, 37, 63, 14, 17, 8, 6}; int i; quicksort( a, 0, 7); printf("Sorted array is: "); for(i=0; i<8; ++i) printf(" %d", a[i]); return 0; } ...

Day 20 Nov

For lab today we used interrupters to instantly change the color of the LED.

Day 11 Oct 3

For todays lab I had to write code where a user would input an angle and a servo would turn to angle, if the angle was invalid a red LED would turn on. However I could not get the red light to turn off after I entered an invalid angle. Here's the code //Sending Multiple Variables at Once //Define LED pins #include <Servo.h> const int SERVO=9; //Servo on Pin 9 Servo myServo; const int RED =12; const int GREEN =11; const int BLUE =10; //int data; char data; //Variables for RGB levels int rval = 0; int gval = 0; int bval = 0; int val = 0; void setup() {  Serial.begin(9600); //Serial Port at 9600 baud  //Set pins as outputs  pinMode(RED, OUTPUT);  pinMode(GREEN, OUTPUT);  pinMode(BLUE, OUTPUT);   myServo.attach(SERVO); } void loop() {  //Keep working as long as data is in the buffer  while (Serial.available() > 0) { data=Serial.read(); //if(data<0 && data> 180) if(data=='0') {  digitalW...

Day 18 Oct 26

Image
The homework was sort of impossible to do since it was really difficult to find adequate earthquake data. I basically just put one earthquake event per day. Here's the output of the program For lab we had to control the car through bluetooth. I forgot to take any pictures for the lab.

Day 17 Oct 24

Image
For this homework we had to modify the seismic code to allow the user to enter the threshold value and print out the events detected Here's a screenshot For lab we had to control the motor using a joystick. Here's a link to the motor working. Here's the code // Arduino pin numbers const int SW_pin = 2; // digital pin connected to switch output const int X_pin = 0; // analog pin connected to X output const int Y_pin = 1; // analog pin connected to Y output int M1_Left = 6; //Motor Input 1 int M1_Right = 5; int M2_Left = 10; int M2_Right = 9; boolean inPin1 = LOW; boolean inPin2 = HIGH; boolean inPin5 = LOW; boolean inPin6 = HIGH; char data; void setup() {     pinMode(M1_Left, OUTPUT);   pinMode(M1_Right , OUTPUT);   pinMode(M2_Right, OUTPUT);   pinMode(M2_Left, OUTPUT);  pinMode(SW_pin, INPUT);  digitalWrite(SW_pin, HIGH);  Serial.begin(115200); void forward(); void reverse(); } void loop() { // Serial.prin...