Posts

day 23

birthday: #include <iostream> #include <string> #include "birthday.h" using namespace std ; int main( void ) { birthday pt1; cout << "input date " << endl; pt1.input(); pt1.print1(); pt1.print2(); return 0 ; } class: #include <iostream> #include <string> using namespace std ; class birthday { public : void input() { cin >> mo >> day >> yr ; } void print1() { cout << mo << "/" << day << "/" << yr << endl; } void print2() { cout << charmonth [ mo - 1 ] << day << ", " << yr ; } private : int mo , day , yr ; //int nummonth[12]={1,2,3,4,5,6,7,8,9,10,11,12}; string charmonth [ 12 ]={ "January " , "Febuaury " , "March " , "April " , "May " , "June " , "July ...

day 22

Python code import serial #Import Serial Library from visual import * #Import all the vPython library arduinoSerialData = serial.Serial('COM3', 9600) #Create an object for the Serial port. Adjust 'com11' to whatever port your arduino is sending to. measuringRod = cylinder( axis=(0,0,10),radius= .5, length=6, color=color.yellow, pos=(-3,0,0)) lengthLabel = label(pos=(0,0,5), text='Target Distance is: ', box=false, height=10) orientation = 0 x = 0 y = 1 z = 2 while (1==1): #Create a loop that continues to read and display the data rate(20)#Tell vpython to run this loop 20 times a second if (arduinoSerialData.inWaiting()>0): #Check to see if a data point is available on the serial port myData = arduinoSerialData.readline() #Read the distance measure as a string myData = myData.strip() mylist = myData.split(',') ax = mylist[x] ay = mylist[y] az = mylist[z] #print ax,ay,az #Print...

day 20

//sd card test printing #include <SD.h> const int POW_PIN = 8; const int CS_PIN = 10; int refresh_rate = 5000; void setup() {   Serial.begin(9600);   Serial.println("Initializing Card");   pinMode(CS_PIN, OUTPUT);   if (!SD.begin(CS_PIN))   {     Serial.println("Card Failure");     return;   }   Serial.println("Card Ready");   File commandFile = SD.open("speed.txt");   if (commandFile)   {    Serial.println("reading command file");   while(commandFile.available())   {     refresh_rate = commandFile.parseInt();   }   Serial.print("refresh rate = " );   Serial.print(refresh_rate);   Serial.println("ms");   commandFile.close();   }   else   {     Serial.println("could not read command file.");     return;   } } void loop() {   long timeStamp = millis();   String dataStr...

Day 21

//data logging pressure and temperature data to SD card with time #include <Wire.h> #include <SD.h> #define BMP180_ADDRESS 0x77 // I2C address of BMP180 const int CS_PIN = 10; const int POW_PIN = 8; int refresh_rate = 5000; const unsigned char OSS = 0; // Oversampling Setting unsigned long t; double temp; int ac1; int ac2; int ac3; unsigned int ac4; unsigned int ac5; unsigned int ac6; int b1; int b2; int mb; int mc; int md; long b5; short temperature; long pressure; const float p0 = 101325; // Pressure at sea level (Pa) float altitude; //-------------------------------------------------------------------------------// void setup() {  Serial.begin(9600);  Wire.begin();  Serial.println("Initializing Card");  pinMode(CS_PIN, OUTPUT);  if(!SD.begin(CS_PIN))  {   Serial.println("Card Failure");   return;  }  Serial.println("Card Ready");   File commandFile = SD.open("speed.txt"); ...

day 19

LAB #include <TimerOne.h> #include "pitches.h" const int BUTTON_INT = 0; const int SPEAKER = 12; volatile int key = NOTE_C2; volatile int octave_multiplier = 1; long timer = 500000; void setup() {   Serial.begin(9600);   pinMode(SPEAKER, OUTPUT);   attachInterrupt(BUTTON_INT, changeKey, RISING);   Timer1.initialize(timer);   Timer1.attachInterrupt(changePitch); } void changeKey() {   octave_multiplier = 1;   if (key == NOTE_C2)     key = NOTE_D2;   else if (key == NOTE_D2)     key = NOTE_E2;   else if (key == NOTE_E2)     key = NOTE_F2;   else if (key == NOTE_F2)     key = NOTE_G2;   else if (key == NOTE_G2)     key = NOTE_A2;   else if (key == NOTE_A2)     key = NOTE_B2;   else if (key == NOTE_B2)     key = NOTE_C2;     timer -= 10000;   Timer1.initialize(timer);     } void changePi...

day 18

Image
LAB: const int BUTTON_INT = 0; const int RED = 11; const int GREEN = 10; const int BLUE = 9; volatile int selectedLED = RED; void setup() {   pinMode (RED, OUTPUT);   pinMode (GREEN, OUTPUT);   pinMode (BLUE, OUTPUT);   attachInterrupt (BUTTON_INT, swap, RISING); } void swap() {   analogWrite (selectedLED, 0);   if (selectedLED == GREEN)   {     selectedLED = RED;   }   else if(selectedLED == RED)   {     selectedLED = BLUE;   }   else if(selectedLED == BLUE)   {     selectedLED = GREEN;   } } void loop() {   for(int i = 0; i<256; i++)   {     analogWrite(selectedLED, i);     delay(10);   }   for(int i = 255; i >= 0; i--)   {     analogWrite(selectedLED, i);     delay(10);   } } Homework: //number of tsunamis the year of the largest wave #include <...

DAY 17

/* ------------------------------------------------------------- */ /* This program stores fingerprint information in a structure. */ /* It then references a function to compute the overall category.*/ #include <stdio.h> /* Define a structure for the fingerprint information. */ /* The order for fingertips is right hand, thumb to pinky, */ /* and left hand, thumb to pinky. The codes are L for loops, */ /* W for whorls, and A for arches. */ struct fingerprint { int ID_number; double overall_category; char fingertip[10]; }; int main(void) { /* Declare and initialize variables. */ struct fingerprint new_print; double compute_category(struct fingerprint f); int k, w_num = 0, l_num = 0, a_num = 0; float w_per, l_per, a_per; /* Specify information for the new fingerprint. */ new_print.ID_number = 2491009; new_print.overall_category = 0; new_print.fingertip[0] = 'W'; new_print.fingertip[1] = 'L...