vectors


Vectors \ Learning \ Wiring ALPHA 1.0 Search wiring.org.co: Language (A-Z) \ Libraries \ Environment \ Learning \ Hardware Examples: Basics, Library, Topics \ Compare Blink Digital read Serial Analog read Serial Switch Photoresistor Fade Statements and comments Setup and Loop Loop Functions Variables Integers and floats True/False Characters and Strings Character classification Datatype conversion Variable scope Arrays Vectors Split a string and convert it to numbers Bidimensional arrays Passing an array to a function Add strings together Appending to Strings Change the case of a string Characters and Strings Compare strings Create strings from other data types Evaluate, look for, and replace characters in a String length() in a String length() and trim() in a String Replace characters or substrings of a string startsWith() and endsWith() in a String Substring in a String Iteration Iterate through digital outputs Iterate through digital inputs Conditionals Logical operators Increment/Decrement Operator precedence Modulo Sine and Cosine Random LED blink LED blink sequence LED swing 7 Segment led numerical LED display Optocoupler: 4N35 Relay 120-240 VAC Light bulb: TRIAC MOSFET: IRLD024 LED Port Tone keyboard Tone melody Tone multiple Tone pitch follower Switch (button) Multiple switches Hall effect sensor distance (proximity) sensor: Parallax ping Transmissive optical sensor Shift Register: 74LS595 Ultrasonic ranger: SFR04/SFR05 Magnetic field sensor: micromag 3-axis Humidity & Temperature: Sparkfun SHT15 Humidity & Temperature: Parallax SHT11 RGB LED matrix: Sparkfun RGB LED backpack Potentiometer Photoresistor Sensor calibration Smooth sensor readings Force Resistor Air quality sensor: MQ135 Infrared ranger (distance/presence): SHARP GP2D12/120 PiezoFilm (touch/vibration): MSIUSA piezo film Phototransistor Microphone (sound sensor) Electret Microphone: Sparkfun Ambient light sensor: Sparkfun TEMT6000 ADXL335 Accelerometer: Sparkfun ADXRS610 Gyroscope: Sparkfun IDG500 Gyroscope: Sparkfun IDG1215 Gyroscope: Sparkfun IXZ500 Gyroscope: Sparkfun LISY300AL Gyroscope: Sparkfun Air pressure: Motorola Infrared ranger & LEDs Potentiometer & LED Low current sensor: Sparkfun ACS712 Current sensor: Sparkfun ACS712 RGB LED Motor speed Stretch sensor & LEDs Light sensor & LED Attending external interrupts Timer LED blink w/timer This example is for Wiring version 0027+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know. Vectors. A vector is a growable array of elements. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. The class Vector includes methods for examining individual elements, comparing, searching and extracting parts. Vector < int > intVector; void setup() { Serial.begin(9600); pinMode(48, OUTPUT); // turn ON wiring hardware LED digitalWrite(48, HIGH); for(int i=0; i<255; i++) { // add 255 elements from 0 to 254 intVector.addElement(i); } Serial.print("The vector's capacity is: "); Serial.println(intVector.capacity(), DEC); // print the vector's capacity if(intVector.contains(15) == true) { // check if contains number 15 Serial.println("The vector contains the element 15"); } Serial.print("The vector's first element is: "); Serial.println(intVector.firstElement(), DEC); // print the vector's first element Serial.print("The vector's index for element 30 is: "); Serial.println(intVector.indexOf(30), DEC); // print the vector's element at position 30 if(intVector.isEmpty() == false) { // check if vector has elements Serial.println("The vector has elements"); } Serial.print("The vector's last element is: "); Serial.println(intVector.lastElement(), DEC); // print the vector's last element Serial.print("The vector's last index of 10 is: "); Serial.println(intVector.lastIndexOf(10), DEC); // print the vector's last index of 10 Serial.print("The vector's size is: "); Serial.println(intVector.size(), DEC); // print the vector's size if(intVector.add(255) == true) { // add element Serial.print("the element was added and now the vector's last element is: "); Serial.println(intVector.lastElement(), DEC); // print the vector's last element } intVector.addElement(256); // add another element Serial.print("now the vector's last element is: "); Serial.println(intVector.lastElement(), DEC); // print the vector's last element intVector.insertElementAt(0, 10); // insert 0 at index 10 int t = intVector.elementAt(10); // get the element at index 10 Serial.print("t is: "); Serial.println(t, DEC); // print its value intVector.remove(10); // remove element at position 10 t = intVector.get(10); // get the element at position 10 Serial.print("t after remove is: "); Serial.println(t, DEC); // print the element at position 10 intVector.removeElementAt(10); // remove element at position 10 t = intVector.get(10); // get the element at position 10 Serial.print("t after removeElementAt is: "); // print the element at position 10 Serial.println(t, DEC); Serial.print("the value of element at position 23 is: "); Serial.println(intVector.get(23), DEC); if(intVector.removeElement(23) == true) { // remove element 23 from the Vector Serial.print("the element at position 23 was removed and the element value after removal is: "); Serial.println(intVector.get(23), DEC); } intVector.setElementAt(10, 5); // set element at postion 5 with value 10 t = intVector.get(5); // get the element at position 10 Serial.print("element at index 5 is now: "); Serial.println(t, DEC); // print the element at position 10 intVector.clear(); // clear all elements in the vector Serial.print("The vector's size after clear is: "); Serial.println(intVector.size(), DEC); // print the vector's size } void loop() { } Wiring is an open project initiated by Hernando Barragán. It is developed by a small team of volunteers. © Info, Processing © Info

Wyszukiwarka

Podobne podstrony:
vector
Vector indexOf
To the Vector Belong Robin Scott Wilson
Vector setSize
2008 T DNA Binary Vectors and Systems
claviceps purpurea oxygen vectors
Vector ensureCapacity
Vector elementAt
java util Vector
Vector contains
Vector removeElementAt
Using Support Vector Machine to Detect Unknown Computer Viruses
Vector
3 Vector Data in Action
Vector removeAllElements
Vector remove
Comparison of cartesian vector control and polar
Vector lastIndexOf

więcej podobnych podstron