Posts

Showing posts from November, 2017

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

Day 16 oct 19

Image
Here is the code for the el nino hw #include<stdio.h> #include<math.h> #define FILENAME "ENS01.txt" #define MAX_SIZE 1000 int main(void) { int k=0, year[MAX_SIZE], qtr[MAX_SIZE], max_k=0,nor_k=0,min_k; double index[MAX_SIZE]; FILE *enso; //READ SENSOR DATA FILE enso = fopen(FILENAME,"r"); if(enso==NULL) printf("Error opening input file. \n"); else { while(fscanf(enso,"%d %d %lf", year+k,qtr+k,index+k)==3) { if(*(index+k)>*(index+max_k)) max_k=k; if(*(index+k)<*(index+min_k)) min_k=k; if(fabs(*(index+nor_k))> fabs(*(index+k))) nor_k=k; k++; } } //print data for max el nion condition printf("Maximun EL Nino Conditions in Data File \n"); printf("Year: %d, Quarter: %d \n", *(year+max_k),*(qtr+max_k)); printf("EL Nino Conditions closest to normal in Data File \n"); printf("Year: %d, Quarter: %d \n\n", *(year+nor_k),*(qtr+nor_k)); //Printout all printf(...