Posts

Showing posts from October, 2018

h bridge dc motor control

Image
const int EN = A0; //enable const int MC1= 7; //motor control 1 const int MC2 = 8; //motor control 2 const int POT = 1; // pot reader const int PWM = 5; //pwm on pin 5  int val=0; //for storing the reading from the pot  int velocity = 0; // for storing the deired velocity (from 0-255)  void setup ()  {   pinMode(EN, OUTPUT);   pinMode(MC1, OUTPUT);   pinMode(MC2, OUTPUT);   pinMode(PWM, OUTPUT);   brake(); //initialize w/ motor stopped  } void loop () {   val = analogRead(POT);   // go forward     if (val > 562)         {           velocity = map (val,563,1023,0,255);           forward(velocity);           }    // go backward    else if (VAL < 462)            {             velocity = map(val,461,0,0255); ...

lab 13 LCD screens

Image
//LCD text with incrementing number //Include the library code: #include <LiquidCrystal.h> //Start the time at 0 int time = 0; //Initialize the library with the numbers of the interface pins LiquidCrystal lcd(8, 9, 4, 5, 6, 7); void setup() {  //Set up the LCD's number of columns and rows:  lcd.begin(16, 2);  //Print a message to the LCD.  lcd.print("ENGR6 Display"); } void loop() {  //Move cursor to second line, first position  lcd.setCursor(0,1);  //Print Current Time  lcd.print(time);  //Wait 1 second  delay(1000);  //Increment the time  time++; } //LCD with Progress Bar //Include the library code: #include <LiquidCrystal.h> //Initialize the library with the numbers of the interface pins LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Create the progress bar characters byte p20[8] = {  B10000,  B10000,  B10000,  B10000,  B10000,  B10000, ...

lab 13 temp sensor and grid code

Image
#include <stdio.h> #include <math.h> #define N 25 #define FILENAME "grid.txt" int main(void) { /* Declare variables. */ int nrows, ncols, i, j, count = 0; double elevation[N][N]; FILE *grid; int highi, highj, lowi, lowj, highest = 0, lowest = 10000; /* Read information from a data file. */ grid = fopen(FILENAME,"r"); if (grid == NULL) printf("Error opening input file\n"); else { fscanf(grid,"%d %d",&nrows,&ncols); for (i=0; i<=nrows-1; i++) for (j=0; j<=ncols-1; j++) { fscanf(grid,"%lf",&elevation[i][j]); if (elevation[i][j] > highest) { highest = elevation[i][j]; highi = i; highj = j; } else if (elevation[i][j] < lowest) { lowest = elevation[i][j]; lowi = i; lowj = j; } } /* Determine and print peak locations. */ printf("Top left point defined as row 0, column 0 \n"); for (i=1; i<=nrows-2; i++) for (j=1; j<=ncols-2; j++) { if ((elevation[i-1...

balloon c code

#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> int main (void) { //Define variables double alt = 0 ; double v = 0 ; double startt = 0 ; double endt = 0 ; double t = startt ; double inct = 0 ; double t_max = 0; double alt_max = 0; //Print title printf(" Balloon Information \n") ; for(t = 60; t < 2880; t++) // Convert hours to minutes { //Tell and allow the user to input the start time printf("Enter start time = "); scanf("%lf", &startt); //Tell and allow the user to input the end time printf("Enter endtime = "); scanf("%lf", &endt); //Tell and allow the user to input the increment between line for time printf("Enter Line Increment of Time = "); scanf("%lf", &inct); //Print table printf(" Altitude Velocity \n"); //Find the balloon information for every 10 minutes and print for (t = startt; t<= ...

day 11 file i/o on arduino

Image
//Simple Serial Printing Test with a Potentiometer const int POT=0; //Pot on analog pin 0 void setup() {  Serial.begin(9600); //Start serial port with baud = 9600 } void loop() {  int val = analogRead(POT); //Read potentiometer  int per = map(val, 0, 1023, 0, 100); //Convert to percentage  Serial.print("Analog Reading: ");  Serial.print(val); //Print raw analog value  Serial.print(" Percentage: ");  Serial.print(per); //Print percentage analog value  Serial.println("%"); //Print % sign and newline  delay(1000); //Wait 1 second, then repeat } ///// reads percentage output when you turn the dial ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Tabular serial printing test with a potentiometer const int POT=0; //Pot on analog pin 0 void setup() {  Serial.begin(9600); //Start Serial Port with Baud = 9600 } void loop()...