t=0 draw=_=>{t||createCanvas(W=720,W) t+=.03 background(W) fill(0) rectMode(CENTER) for(y=0;y
float i,t,d; void setup(){size(720,720);colorMode(HSB);} void draw(){ clear(); t+=.01; for(i=0;i<100;i++){ d=(t+i/100)%1; fill(noise(i,(int)d,2)*255,99,192,255-d*255); square((int)(noise(i,(int)d)*24)*30,(int)(noise(i,(int)d,1)*24)*30,20); } } #つぶやきProcessing
“float t,i,N; void setup(){size(720,720);} void draw(){background(-1);t+=.01;for(i=9;i>0;i--){rotate(t);rect(i-9,i-9,i*i,i*i);}rotate(-9*t);for(int y=0;y<800;y+=80)for(int x=0;x<800;x+=80)copy(get(),0,0,80,80,x/160*160,y/160*160,80-x/80%2*160,80-y/80%2*160);} #つぶやきProcessing”
Integrals General - We all need some integral training. Post some hard integrals and then solve some hard integrals. \int_{0}^{1} \int_{y}^{1} \frac{sin(x)}{x}dxdy \int_{0}^{\infty} sin(x^{2}) \int \sqrt{tan(x)}dx I hope that shit worked, it was my first attempt at LaTeX, took me like 10 minutes n' shit.
/* 4 digit 7 segment display: http://www.sparkfun.com/products/9483 Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf 7 segments + 4 digits + 1 colon = 12 pins required for full control */ // modified connexion by niq_ro from http://nicuflorica.blogspot.com // for my Luckylight KW4-563ASA // dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf int digit1 = 11; //PWM Display pin 12 (digit1 is common anonds A1 from right side) int digit2 = 10; //PWM Display pin 9 (digit2 is common A2) int digit3 = 9; //PWM Display pin 8 (digit3 is common anods A3) int digit4 = 6; //PWM Display pin 6 (digit4 is common anods, from left side) //Pin mapping from Arduino to the ATmega DIP28 if you need it //http://www.arduino.cc/en/Hacking/PinMapping int segA = 2; //Display pin 11 int segB = 3; //Display pin 7 int segC = 4; //Display pin 4 int segD = 5; //Display pin 2 int segE = 12; //Display pin 1 int segF = 7; //Display pin 10 int segG = 8; //Display pin 5 int segDP = 13; // Display pin 3 #include #include "RTClib.h" RTC_DS1307 RTC; // Date and time functions using a DS1307 RTC connected via I2C and Wire lib // original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/ // add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/ // add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm byte SW0 = A0; byte SW1 = A1; byte SW2 = A2; // use for hexa in zecimal conversion int zh, uh, ore; int zm, um, miniti; void setup() { // Serial.begin(57600); Wire.begin(); RTC.begin(); // RTC.adjust(DateTime(__DATE__, __TIME__)); // if you need set clock... just remove // from line above this // part code for flashing LED Wire.beginTransmission(0x68); Wire.write(0x07); // move pointer to SQW address // Wire.write(0x00); // turns the SQW pin off Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz // Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz Wire.endTransmission(); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } // dht.begin(); pinMode(segA, OUTPUT); pinMode(segB, OUTPUT); pinMode(segC, OUTPUT); pinMode(segD, OUTPUT); pinMode(segE, OUTPUT); pinMode(segF, OUTPUT); pinMode(segG, OUTPUT); pinMode(segDP, OUTPUT); pinMode(digit1, OUTPUT); pinMode(digit2, OUTPUT); pinMode(digit3, OUTPUT); pinMode(digit4, OUTPUT); // pinMode(13, OUTPUT); Serial.begin(9600); Serial.println("test for niq_ro"); pinMode(SW0, INPUT); // for this use a slide switch pinMode(SW1, INPUT); // N.O. push button switch pinMode(SW2, INPUT); // N.O. push button switch digitalWrite(SW0, HIGH); // pull-ups on digitalWrite(SW1, HIGH); digitalWrite(SW2, HIGH); } void loop() { digitalWrite(segDP, HIGH); DateTime now = RTC.now(); int timp = now.hour()*100+now.minute(); // int timp = (now.minute(), DEC); // displayNumber(12); // this is number to diplay // int timp = 1234; Serial.print(now.hour(), DEC); Serial.print(":"); Serial.print(now.minute(), DEC); Serial.print(" -> "); Serial.print(timp); Serial.println(" !"); // display parts for(int i = 250 ; i >0 ; i--) { if (timp >= 1000) displayNumber01(timp); else displayNumber02(timp); } for(int i = 250 ; i >0 ; i--) { if (timp >= 1000) displayNumber03(timp); else displayNumber04(timp); } if (!(digitalRead(SW0))) set_time(); // hold the switch to set time } void set_time() { byte minutes1 = 0; byte hours1 = 0; byte minutes = 0; byte hours = 0; while (!digitalRead(SW0)) // set time switch must be released to exit { minutes1=minutes; hours1=hours; while (!digitalRead(SW1)) // set minutes { minutes++; // converting hexa in zecimal: zh = hours / 16; uh = hours - 16 * zh ; ore = 10 * zh + uh; zm = minutes / 16; um = minutes - 16 * zm ; miniti = 10 * zm + um; for(int i = 20 ; i >0 ; i--) { displayNumber01(ore*100+miniti); } if ((minutes & 0x0f) > 9) minutes = minutes + 6; if (minutes > 0x59) minutes = 0; Serial.print("Minutes = "); if (minutes >= 9) Serial.print("0"); Serial.println(minutes, HEX); delay(150); } while (!digitalRead(SW2)) // set hours { hours++; // converting hexa in zecimal: zh = hours / 16; uh = hours - 16 * zh ; ore = 10 * zh + uh; zm = minutes / 16; um = minutes - 16 * zm ; miniti = 10 * zm + um; for(int i = 20 ; i >0 ; i--) { displayNumber01(ore*100+miniti); } if ((hours & 0x0f) > 9) hours = hours + 6; if (hours > 0x23) hours = 0; Serial.print("Hours = "); if (hours <= 9) Serial.print("0"); Serial.println(hours, HEX); delay(150); } Wire.beginTransmission(0x68); // activate DS1307 Wire.write(0); // where to begin Wire.write(0x00); //seconds Wire.write(minutes); //minutes Wire.write(0x80 | hours); //hours (24hr time) Wire.write(0x06); // Day 01-07 Wire.write(0x01); // Date 0-31 Wire.write(0x05); // month 0-12 Wire.write(0x09); // Year 00-99 Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7. Wire.endTransmission(); // converting hexa in zecimal: zh = hours / 16; uh = hours - 16 * zh ; ore = 10 * zh + uh; zm = minutes / 16; um = minutes - 16 * zm ; miniti = 10 * zm + um; for(int i = 20 ; i >0 ; i--) { displayNumber01(ore*100+miniti); } // delay(150); } } void displayNumber01(int toDisplay) { #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW for(int digit = 4 ; digit > 0 ; digit--) { //Turn on a digit for a short amount of time switch(digit) { case 1: digitalWrite(digit1, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 2: digitalWrite(digit2, DIGIT_ON); digitalWrite(segDP, LOW); break; case 3: digitalWrite(digit3, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 4: digitalWrite(digit4, DIGIT_ON); digitalWrite(segDP, HIGH); break; } lightNumber(toDisplay % 10); toDisplay /= 10; delayMicroseconds(DISPLAY_BRIGHTNESS); //Turn off all segments lightNumber(10); //Turn off all digits digitalWrite(digit1, DIGIT_OFF); digitalWrite(digit2, DIGIT_OFF); digitalWrite(digit3, DIGIT_OFF); digitalWrite(digit4, DIGIT_OFF); } } void displayNumber02(int toDisplay) { #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW for(int digit = 4 ; digit > 0 ; digit--) { //Turn on a digit for a short amount of time switch(digit) { case 1: lightNumber(10); digitalWrite(segDP, HIGH); break; case 2: digitalWrite(digit2, DIGIT_ON); digitalWrite(segDP, LOW); break; case 3: digitalWrite(digit3, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 4: digitalWrite(digit4, DIGIT_ON); digitalWrite(segDP, HIGH); break; } lightNumber(toDisplay % 10); toDisplay /= 10; delayMicroseconds(DISPLAY_BRIGHTNESS); //Turn off all segments lightNumber(10); //Turn off all digits digitalWrite(digit1, DIGIT_OFF); digitalWrite(digit2, DIGIT_OFF); digitalWrite(digit3, DIGIT_OFF); digitalWrite(digit4, DIGIT_OFF); } } void displayNumber03(int toDisplay) { #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW for(int digit = 4 ; digit > 0 ; digit--) { //Turn on a digit for a short amount of time switch(digit) { case 1: digitalWrite(digit1, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 2: digitalWrite(digit2, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 3: digitalWrite(digit3, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 4: digitalWrite(digit4, DIGIT_ON); digitalWrite(segDP, HIGH); break; } lightNumber(toDisplay % 10); toDisplay /= 10; delayMicroseconds(DISPLAY_BRIGHTNESS); //Turn off all segments lightNumber(10); //Turn off all digits digitalWrite(digit1, DIGIT_OFF); digitalWrite(digit2, DIGIT_OFF); digitalWrite(digit3, DIGIT_OFF); digitalWrite(digit4, DIGIT_OFF); } } void displayNumber04(int toDisplay) { #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW for(int digit = 4 ; digit > 0 ; digit--) { //Turn on a digit for a short amount of time switch(digit) { case 1: lightNumber(10); digitalWrite(segDP, HIGH); break; case 2: digitalWrite(digit2, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 3: digitalWrite(digit3, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 4: digitalWrite(digit4, DIGIT_ON); digitalWrite(segDP, HIGH); break; } lightNumber(toDisplay % 10); toDisplay /= 10; delayMicroseconds(DISPLAY_BRIGHTNESS); //Turn off all segments lightNumber(10); //Turn off all digits digitalWrite(digit1, DIGIT_OFF); digitalWrite(digit2, DIGIT_OFF); digitalWrite(digit3, DIGIT_OFF); digitalWrite(digit4, DIGIT_OFF); } } //Given a number, turns on those segments //If number == 10, then turn off number void lightNumber(int numberToDisplay) { #define SEGMENT_ON LOW #define SEGMENT_OFF HIGH switch (numberToDisplay){ case 0: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_ON); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_OFF); break; case 1: digitalWrite(segA, SEGMENT_OFF); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_OFF); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_OFF); break; case 2: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_OFF); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_ON); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_ON); break; case 3: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_ON); break; case 4: digitalWrite(segA, SEGMENT_OFF); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_OFF); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; case 5: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_OFF); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; case 6: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_OFF); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_ON); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; case 7: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_OFF); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_OFF); break; case 8: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_ON); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; case 9: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; // all segment are ON case 10: digitalWrite(segA, SEGMENT_OFF); digitalWrite(segB, SEGMENT_OFF); digitalWrite(segC, SEGMENT_OFF); digitalWrite(segD, SEGMENT_OFF); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_OFF); break; } } I made a litle movie named manual adjust for RTC clock with Arduino and 7-segment LED display Note: Original article in roumanian language is Afisaje LED cu 7 segmente si.. Arduino (IV)!!! 11.10.2016 I correct sketch for display 10:00 case.. 07.02.2017 Now, I pun on my Github channel sketch for cathode comon display, see github.com/tehniq3/multiplexedclock
Graphic Design, Illustration, Advertising, Adobe Photoshop, Wacom Cintiq
#fashion #fashionista #fashionable #aesthetic #2000s #2000sfashion #socceraesthetic #football
- Conseils et expertise Tollens pour les particuliers et les professionnels - Fabricant et distributeur de peintures, revêtements sol et mur et solutions d'isolation ITE.
1 Teens Int TEST Term 2 (Files 3-4) Name___________ Surname______________ Score: _____ /100 = ____% LISTENING 1 Listen to the conversation about playing a musical instrument. Who said the following? Write I(Ian) or K (Kate) or N (Neither). 1 I found it difficult to produce sounds when I started. ____ 2 My teacher wasn’t impressed by the sound I made. ____ 3 I used to play in a band. Auto-graded practice and assessment of "Teens Int Test Term 2" for in-class and distance learning.
030 | Feldweg im Herbst
Benrath Palace
Welcome to the Arduino Workshop, where you'll be able to follow our guided course which covers everything you'll need to know in order to create your own Arduino projects and become a leveled up maker. My name is Sam and along with being a maker myself, I also enjoy teaching others how to use different technology and create amazing projects. Along with the course videos themselves, you can find all of the related course material such as code examples, circuit diagrams, images, and other resources. We'll be working with Arduino so you'll need an Arduino board to follow this course. We'll be introducing many different concepts including working with various types of hardware such as sensors, displays, and general electronics components, and the kit we're using for all of this is the Sparkfun Inventors Kit. If you are not in Australia, you can grab from Sparkfun directly and have it shipped to you almost anywhere in the world. Course Goals: Understand what an Arduino is and how it works Learn how to use an Arduino safely Program your Arduino using code that you've written in the Arduino IDE (Integrated Development Environment) Learn programming concepts using C and C++ along with Arduino specific programming Understand best practice concepts for programming and prototyping Use a wide variety of hardware and components and prototype your projects using a breadboard Build your own innovative project with Arduino When you're ready, let's begin the Arduino Workshop! If you run into any issues throughout this workshop, then please reach out to us on our forum. We're full-time makers and are here to help. Chapter 1: Introduction to Arduino 1.0 Chapter Overview In this chapter you'll learn about: What is Arduino Different types of Arduino boards How does the Arduino Uno board work and why it's so popular What is a microcontroller How to use the Arduino IDE (Integrated Development Environment) Powering and connecting your Arduino to your computer Uploading programs to your Arduino board By the end of this chapter, you will have uploaded your first program to your Arduino board to control an LED. 1.1 What is Arduino? In this section, we look at what is Arduino, what it's good for makers, and some of the different types of Arduino boards available. Section Resources: Example Arduino Uno Variations 1.2 What is a Microcontroller? In this section, we'll be looking at what is a microcontroller (the chip at the heart of any Arduino board), an overview of how they work, and how it integrates with the Arduino environment. 1.3 The Arduino Uno In this section, you'll learn about the features and capabilities of the Arduino Uno board, how the layout of the board can affect your project, and why the Uno is such a great all-rounder. 1.4 Arduino IDE and the Language In this section, we'll take a look at the Arduino IDE, which is where you write the code for your Arduino, upload it, and communicate with your board. We'll also cover the programming language that Arduino IDE uses, and where to download it. Section Resources: You can download the Arduino IDE from the Arduino website. 1.5 Powering and Connecting Your Arduino In this section, you'll be learning about the various ways to power your Arduino, and how to connect it up to your computer for uploading your programs, and communicating to the computer using the serial port. Section Resources: Arduino Power Layout 1.6 Hello World Example In the final section of this chapter, we'll talk through using the Arduino IDE to upload your first program to your Arduino board. Section Resources: Source code for 'Hello World' void setup() { pinMode(13, OUTPUT); //setup pin 13 as an output } void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH outputs 5V) delay(500); // wait for 500 milliseconds digitalWrite(13, LOW); // turn the LED off (LOW outputs 0V) delay(500); // wait for 500 milliseconds } Chapter 2: Using Inputs and Outputs 2.0 Chapter Overview In this chapter you'll learn about: How to properly structure your code Using variables to write more capable programs Building circuits using a breadboard Reading inputs and controlling outputs using the digital and analog pins Communicating via the serial port By the end of the chapter, you will have created an input interface for your Arduino, using the Serial Monitor to display the data. 2.1 Program Structure In this section, we'll be learning about how to properly structure code using indentations, nested levels, and semicolons. Section Resources: Example Program Structure 2.2 Using Variables In this section, we'll explore the use of variables, which will allow you to write more sophisticated code. Section Resources: Arduino Reference Datatypes: If you're interested in learning more about the various datatypes that Arduino supports, check out the reference page. 2.3 Building Your First Circuit Using a Breadboard In this section, we'll look at using different components such as LEDs, buttons, jumper wires, resistors, and a breadboard to construct a circuit. Section Resources: Further Reading If you'd like to know more about how electronic components work, check out the Analogue Electronics Crash Course and All About LEDs tutorials for more in-depth information. Wiring Diagram 2.4 Using Digital Pins In this section, we'll learn how to use the digital pins to read inputs and control outputs. Section Resources: Source code for 'LED Button' int buttonPin = 2; int ledPin = 3; void setup() { // setup pin modes pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); } void loop() { // read state of buttonPin and store it as the buttonState variable int buttonState = digitalRead(buttonPin); // write the value of buttonState to ledPin digitalWrite(ledPin, buttonState); } Wiring Diagram for 'Digital Pins' 2.5 Using Analogue Pins In this section, we'll learn how to use the analog pins to read inputs and control outputs. Section Resources: Source Code for 'Blink Rate Control' int ledPin = 3; int potPin = A0; void setup() { // setup pin modes pinMode(ledPin, OUTPUT); pinMode(potPin, INPUT); } void loop() { // read the value of the pot and store it as potValue int potValue = analogRead(potPin); // turn led on and wait for the time equal to potValue digitalWrite(ledPin, HIGH); delay(potValue); // re-read the value of the pot and store it as potValue potValue = analogRead(potPin); // turn led off and wait for the time equal to potValue digitalWrite(ledPin, LOW); delay(potValue); } Source Code for 'LED Brightness Control' int ledPin = 3; int potPin = A0; void setup() { // setup pin modes pinMode(ledPin, OUTPUT); pinMode(potPin, INPUT); } void loop() { // read the value of the pot, divide it by 4, and store it as potValue int potValue = analogRead(potPin) / 4; // turn led on with the value of potValue analogWrite(ledPin, potValue); } Wiring Diagram for 'Analogue Pins' 2.6 Displaying Information Using the Serial Port In this section, we'll be looking at using the serial port on the Arduino to communicate with a computer via USB. Section Resources: Source Code for 'Serial Monitoring' int ledPin = 3; int buttonPin = 2; int potPin = A0; void setup() { // setup pin modes pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); pinMode(potPin, INPUT); // initialise serial port with baud rate of 9600 Serial.begin(9600); } void loop() { // read the state of buttonPin and store it as buttonState (0 or 1) int buttonState = digitalRead(buttonPin); // read the value of the pot, divide it by 4, and store it as potValue int potValue = analogRead(potPin); int filteredPotValue = potValue / 4; // turn led on with the value of potValue analogWrite(ledPin,filteredPotValue); // print the value of the button Serial.print("Button: "); Serial.print(buttonState); Serial.print(" "); // print the value of the pot Serial.print("Pot: "); Serial.print(potValue); Serial.print(" "); // print the value of the pot / 4 with a line return at the end Serial.print("Pot/4: "); Serial.println(filteredPotValue); } Wiring Diagram for 'Serial Reading' Chapter 3: Decision Making and Using Logic 3.0 Chapter Overview In this chapter you'll learn about: Using 'If' statements Using 'while' loops Using 'for' loops Using 'Switch cases' Using maths in Arduino Creating functions Creating sophisticated code By the end of this chapter, you will have created your very own calculator using different functions, loops, and Serial functions. 3.1 'If' Statements In this section, we'll be looking at using 'If' statements, which are the backbone of decision-making for microcontrollers. Section Resources: Source Code for 'Toggle Switch' // pin definitions int ledPin = 3; int buttonPin = 2; // global variables int toggleState; int lastButtonState = 1; long unsigned int lastPress; int debounceTime = 20; void setup() { // setup pin modes pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); } void loop() { int buttonState = digitalRead(buttonPin); //read the state of buttonPin and store it as buttonState (0 or 1) if((millis() - lastPress) > debounceTime) //if the time between the last buttonChange is greater than the debounceTime { lastPress = millis(); //update lastPress if(buttonState == 0 && lastButtonState == 1) //if button is pressed and was released last change { toggleState =! toggleState; //toggle the LED state digitalWrite(ledPin, toggleState); lastButtonState = 0; //record the lastButtonState } if(buttonState == 1 && lastButtonState == 0) //if button is not pressed, and was pressed last change { lastButtonState = 1; //record the lastButtonState } } } Wiring Diagram for 'Digital Pins' 3.2 'While' Loops In this section, you'll learn about using 'while' loops and how to use them to change the structure of your code. Section Resources: Source Code for 'LED Flash Rate' // pin definitions int ledPin = 3; int buttonPin = 2; // global variables int toggleState; int buttonState =1; void setup() { // setup pin modes pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); } void loop() { buttonState = digitalRead(buttonPin); while(buttonState == 0) { toggleState =! toggleState; digitalWrite(ledPin, toggleState); delay(50); buttonState = digitalRead(buttonPin); } toggleState =! toggleState; digitalWrite(ledPin, toggleState); delay(200); } Wiring Diagram for 'LED Flash Rate' 3.3 'For' Loops In this section, you'll look at 'for' loops which you can use to control the flow of your program. Section Resources: Source Code for 'LED Pulse' // pin definitions int ledPin = 3; // global variables int rampTime = 2; void setup() { // setup pin modes pinMode(ledPin, OUTPUT); //initialise serial port Serial.begin(9600); } void loop() { // ramp LED brightness up to max for(int i = 0; i<256; i++) { analogWrite(ledPin, i); delay(rampTime); Serial.println(i); } // ramp LED brightness down to 0 for(int i = 255; i>0; i--) { analogWrite(ledPin, i); delay(rampTime); Serial.println(i); } } Wiring Diagram for 'LED Pulse' 3.4 Using 'Switch' Cases In this section, we'll dive into using 'switch' cases to implement comparative lists and outcomes. Section Resources: Source Code for 'Potentiometer Switch Case' // pin definitions int potPin = A0; // declare global variables int lastPotValue; void setup() { // set pin modes pinMode(potPin, INPUT); //initialise Serial port Serial.begin(9600); } void loop() { // read potPin and divide by 255 to give 5 possible readings int potValue = analogRead(potPin) / 255; // if something has changed since last value if(potValue != lastPotValue) { // enter switch case switch(potValue) { case 0: Serial.println("Very Low"); break; case 1: Serial.println("Low"); break; case 2: Serial.println("Moderate"); break; case 3: Serial.println("High"); break; case 4: Serial.println("Extreme"); break; default: Serial.println("error!"); break; } lastPotValue = potValue; } } Wiring Diagram for 'Potentiometer Switch Case' 3.5 Using Maths In this section, we'll look at how to use different mathematic functions and methods in Arduino. Section Resources: Example for 'Maths Functions' x = y + 3; x = y - 7; x = y * 6; x = y / 4; 3.6 Creating Functions In this section, we'll be learning about using and creating your own functions to write modular, reusable code. Section Resources: Source Code for 'Hypotenuse Calculator' *Update 8/1/18: I've updated the sketch for the hypotenuse calculater which is reflected in the code below. It provides rejection for non-integer values and some extra feedback. void setup() { //initialise Serial port Serial.begin(9600); } void loop() { int a; int b; float result; //print instructions, and wait until there is something in the serial buffer Serial.print("Enter a side value: "); while(!Serial.available()); a = readSerial(); if(a == 0) { return; } Serial.print("Enter the other side value: "); while(!Serial.available()); b = readSerial(); if(b == 0) { return; } findSide(a,b); Serial.println(); } //readSerial takes the next integer in the Serial buffer, clears the buffer, then returns it int readSerial() { int i = Serial.parseInt(); //checks if the received value is a valid integer if(i < 1 || (i%1 != 0)) { Serial.println("That isn't a valid integer"); return 0; } Serial.println(i); Serial.parseInt(); return i; } void findSide(int x, int y) { //calculate C squared by A squared + B squared float hypotenuse = sqrt(x*x + y*y); //print out the result Serial.print("Hypotenuse = "); Serial.println(hypotenuse); } Chapter 4: Data Manipulation and EEPROM 4.0 Chapter Overview In this chapter you'll learn about: Using variables within Arrays Using arithmetic, relational, logical, and assignment operators Manipulating data using bit-wise operators and logic Storing information between resets using EEPROM By the end of this chapter, you will have created an LED sequencing display using arrays, operators, and EEPROM storage. 4.1 Arrays In this section, we'll look at using arrays to store data, which allows for more powerful variable manipulation. Section Resources: Source Code for 'LED Sequencer' int ledArray[] = {2,3,4,5,6,7,8,9}; int delayTime = 50; void setup() { //initialise ledArray as outputs for(int i = 0; i<10; i++) { pinMode(ledArray[i], OUTPUT); } } void loop() { //turn LEDs on from 0-7 for(int i = 0; i <= 7; i++) { digitalWrite(ledArray[i], HIGH); delay(delayTime); } //turn LEDs off from 7-0 for(int i = 7; i >= 0; i--) { digitalWrite(ledArray[i], LOW); delay(delayTime*5); } } Wiring Diagram 4.2 Operators In this section, we're going to look at using arithmetic, relational, logical, and assignment operators. These are all used for comparing and evaluating data. Section Resources: Relation Operators Reference x = 4 y = 6 (x == y) false (x != y) true (x > y) false (x < y) true (x >= y) false (x <= y) true Logical Operators x = 0 y = 1 (x && y) false (x || y) true x = !x x now equals 1 (not 0) Assignment Operators i += 2 same as i = i+2 i -= 2 same as i = i-2 i *= 2 same as i = i*2 i /= 2 same as i = i/2 4.3 Bit Math In this section, you'll be learning about control individual bits within bytes using bit-wise operators and logic. Section Resources: Bitwise Operator Examples /*This section is a logic reference example. This is not valid code and won't compile on your Arduino //AND x = 0011 0100 y = 0101 1101 x & y = 0001 0100 //OR x = 0011 0100 y = 0101 1101 x | y = 0111 1101 //XOR x = 0011 0100 y = 0101 1101 x ^ y = 0110 1001 //NOT x = 0011 0100 ~x = 1100 1011 y = 0101 1101 ~y = 1010 0010 //SHIFT LEFT x = 0011 0100 x << 2 = 1101 0000 y = 0101 1101 y << 2 = 0111 0100 //SHIFT RIGHT x = 0011 0100 x >> 2 = 0000 1101 y = 0101 1101 y >> 2 = 0001 0111 */ Truth Tables Source Code for 'AND, OR, XOR Calculator' const int dataPin = 6; const int clockPin = 7; const int latchPin = 8; byte ledMap = 0b11111111; int delayTime = 3000; void setup() { // put your setup code here, to run once: pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(latchPin, OUTPUT); Serial.begin(9600); shiftWrite(0x00); Serial.println("Enter a number between 0-255"); } void loop() { if(Serial.available()) { int inputVal = Serial.parseInt(); if(inputVal > 255) { Serial.println("Uh oh, try again"); Serial.println("Enter a number between 0-255"); return; } Serial.print("DECIMAL: "); Serial.println(inputVal); Serial.print("BINARY: "); Serial.println(inputVal, BIN); Serial.println(); Serial.print("AND result: "); Serial.println(ledMap & inputVal, BIN); shiftWrite(ledMap & inputVal); delay(delayTime); Serial.print("OR result: "); Serial.println(ledMap | inputVal, BIN); shiftWrite(ledMap | inputVal); delay(delayTime); Serial.print("XOR result: "); Serial.println(ledMap ^ inputVal, BIN); shiftWrite(ledMap ^ inputVal); delay(delayTime); Serial.println(); Serial.println("Enter a number between 0-255"); } } void shiftWrite(byte value) { digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, value); digitalWrite(latchPin, HIGH); } Wiring Diagram for 'AND, OR, XOR Calculator' 4.4 EEPROM In this section, we'll learn about storing data in the non-volatile memory known as EEPROM. This allows data to be retained when power is disconnected and accessed later. Section Resources: Source Code for 'EEPROM Counter' #include
****** A lot of people land on this page. Welcome. There are a few updates on this project (the last being here.) so it's worth checking through the blog for updates. Thanks ****** It's been a great summer here in the UK. I built myself something I'd always wanted. A bit of a water feature in my garden. The sound of trickling water whilst relaxing in the garden ... ahhhh ! Well, I didn't like the thought of the pump running all night, wasting all that precious energy, so a solution was required.... The usual thoughts of a photodiode (even an led works as a photodiode, try it!) or LDR and comparator were soon dispelled, as I'd done such things as a kid, and it's a horrible thing to set up. Clouds causing shadows, neighbours outside lights switching it on etc etc ... no , we need something a little more sophisticated. Now, a guy called Paul had done the same thing, but backwards (switching something on at dusk, and off at dawn), and his website here shows a rather nice unit built using recycled bits and pieces. "Just the job".. except I need more coding experience, so I blatantly copy some of Paul's thoughts and the use of the Timelord library. Although I love the idea of recycling the display, I just don't have anything to recycle at present, other than the usual 2 x 16 LCD I've removed from a DAB radio, and a nice rotary encoder, so we'll go with those. Now, keeping time.... This is a DS1307 module, purchased at very little expense (but a bit of a wait) on eBay. It's a fully fledged real-time clock, which sends it's data via an I2C interface. Just the job. On the rear of this fella is a button cell holder. Just beware. Order yours with the battery. You can get a version which takes an ordinary 2023 Lithium coin cell, or an LIR2023 Lithium-ion coin cell, which charges off the supplied 3.3 or 5 volts. Don't try and charge an ordinary 2023 cell. It won't be pretty. OK, so that's our time keeping sorted. So, time to conjure up some hardware.... My 5v supply is a little buck converter, which is driven from the 24VAC from the pond transformer. The Arduino (Nano in this example) is mounted on a bit of perf board, along with a relay module and the DS1307 RTC board. Now copy the code into your IDE, and alter the LATITUDE and LONGITUDE constants to your position on the planet. Google maps comes in handy here, or just pop outside with a GPS. Upload the code (below) and your display should show something like this. American users may wish to note the date is in the UK standard (DD/MM/YYYY), you can, of course, alter the code to suit your own preferred format. Now, if that's not UTC (and unless you're in the UK in winter, or your PC is set to UTC, it won't be) press and hold the button for 5 seconds. When you release the button the display will show "Set Year". You can alter this using the rotary encoder. If the encoder works back to front, reverse the wires to pins D2 & D3 on the Arduino board. Pressing the button moves the menu on to set Month. Pressing again, set the day, then hour and then minute. Once the minute is set the RTC is set, and the clock display will revert after 1 second. Excellent. The clock is now set and running. Pressing and releasing the button once will display the current calculated sun rise and sunset time. If you wait the display will revert back to the clock after a few seconds. Pressing again whilst the sunrise and sunset times are display will allow you to alter the mode of the clock. Auto switches the output on when the sun rises, and off when it sets. On switches the output on permanently. Finally off leaves the output off. Finally, mount the whole shooting match on the wall, make it neat and go for a pint or two to celebrate! Here's the code: // Dawn & Dusk controller. // 16th August 2014. // (C) A.G.Doswell 2014 // // Date and time functions using a DS1307 RTC connected via I2C and Wire lib // // Designed to control a relay connected to pin A3. Pin goes low during daylight hours and high during night. Relay uses active low, so is // "On" during the day. This is connected to the fountain pump in my garden. // // Time is set using a rotary encoder with integral push button. The Encoder is connected to interrupt pins D2 & D3 (and GND), // and the push button to pin analogue 0 (and GND) // The RTC is connections are: Analogue pin 4 to SDA. Connect analogue pin 5 to SCL. // A 2 x 16 LCD display is connected as follows (NOTE. This is NOT conventional, as interrupt pins are required for the encoder) // Arduino LCD // D4 DB7 // D5 DB6 // D6 DB5 // D7 DB4 // D12 RS // D13 E // // Use: Pressing and holding the button will enter the clock set mode (on release of the button). Clock is set using the rotary encoder. // The clock must be set to UTC. // Pressing and releasing the button quickly will display the current sun rise and sun set times. Pressing the button again will enter the mode select menu. // Modes are AUTO: On when the sun rises, off when it sets. // ON: Permanently ON // OFF: Permanently OFF (Who'd have guessed it?) // // Change the LATTITUDE and LONGITUDE constant to your location. #include #include "RTClib.h" // from https://github.com/adafruit/RTClib #include #include // from http://www.pjrc.com/teensy/td_libs_Encoder.html #include // from http://swfltek.com/arduino/timelord.html. When adding it to your IDE, rename the file, removing the "-depreciated" RTC_DS1307 RTC; // Tells the RTC library that we're using a DS1307 RTC Encoder knob(2, 3); //encoder connected to pins 2 and 3 (and ground) LiquidCrystal lcd(12, 13, 7, 6, 5, 4); // I used an odd pin combination because I need pin 2 and 3 for the interrupts. //the variables provide the holding values for the set clock routine int setyeartemp; int setmonthtemp; int setdaytemp; int sethourstemp; int setminstemp; int setsecs = 0; int maxday; // maximum number of days in the given month int TimeMins; // number of seconds since midnight int TimerMode = 2; //mode 0=Off 1=On 2=Auto int TimeOut = 10; int TimeOutCounter; // These variables are for the push button routine int buttonstate = 0; //flag to see if the button has been pressed, used internal on the subroutine only int pushlengthset = 3000; // value for a long push in mS int pushlength = pushlengthset; // set default pushlength int pushstart = 0;// sets default push value for the button going low int pushstop = 0;// sets the default value for when the button goes back high int knobval; // value for the rotation of the knob boolean buttonflag = false; // default value for the button flag const int TIMEZONE = 0; //UTC const float LATITUDE = 51.89, LONGITUDE = -2.04; // set YOUR position here int Sunrise, Sunset; //sunrise and sunset expressed as minute of day (0-1439) TimeLord myLord; // TimeLord Object, Global variable byte sunTime[] = {0, 0, 0, 1, 1, 13}; // 17 Oct 2013 int SunriseHour, SunriseMin, SunsetHour, SunsetMin; //Variables used to make a decent display of our sunset and sunrise time. void setup () { //Serial.begin(57600); //start debug serial interface Wire.begin(); //start I2C interface RTC.begin(); //start RTC interface lcd.begin(16,2); //Start LCD (defined as 16 x 2 characters) lcd.clear(); pinMode(A0,INPUT);//push button on encoder connected to A0 (and GND) digitalWrite(A0,HIGH); //Pull A0 high pinMode(A3,OUTPUT); //Relay connected to A3 digitalWrite (A3, HIGH); //sets relay off (default condition) //Checks to see if the RTC is runnning, and if not, sets the time to the time this sketch was compiled. if (! RTC.isrunning()) { RTC.adjust(DateTime(__DATE__, __TIME__)); } //Timelord initialisation myLord.TimeZone(TIMEZONE * 60); myLord.Position(LATITUDE, LONGITUDE); CalcSun (); } void loop () { DateTime now = RTC.now(); //get time from RTC //Display current time lcd.setCursor (0,0); lcd.print(now.day(), DEC); lcd.print('/'); lcd.print(now.month()); lcd.print('/'); lcd.print(now.year(), DEC); lcd.print(" "); lcd.setCursor (0,1); lcd.print(now.hour(), DEC); lcd.print(':'); if (now.minute() <10) { lcd.print("0"); } lcd.print(now.minute(), DEC); lcd.print(':'); if (now.second() <10) { lcd.print("0"); } lcd.print(now.second()); lcd.print(" "); //current time in minutes since midnight (used to check against sunrise/sunset easily) TimeMins = (now.hour() * 60) + now.minute(); // Calculate sun times once a day at a minute past midnight if (TimeMins == 1) { CalcSun (); } if (TimerMode ==2) { if (TimeMins >= Sunrise && TimeMins <=Sunset-1) { //If it's after sunrise and before sunset, switch our relay on digitalWrite (A3, LOW); lcd.setCursor (13,1); lcd.print ("On "); } else { //otherwise switch it off digitalWrite (A3, HIGH); lcd.setCursor (13,1); lcd.print ("Off"); } } if (TimerMode ==0) { digitalWrite (A3, HIGH); lcd.setCursor (13,1); lcd.print ("Off"); } if (TimerMode ==1) { digitalWrite (A3, LOW); lcd.setCursor (13,1); lcd.print ("On "); } pushlength = pushlengthset; pushlength = getpushlength (); delay (10); if (pushlength pushlengthset) { lcd.clear(); DateTime now = RTC.now(); setyeartemp=now.year(),DEC; setmonthtemp=now.month(),DEC; setdaytemp=now.day(),DEC; sethourstemp=now.hour(),DEC; setminstemp=now.minute(),DEC; setclock(); pushlength = pushlengthset; }; } //sets the clock void setclock (){ setyear (); lcd.clear (); setmonth (); lcd.clear (); setday (); lcd.clear (); sethours (); lcd.clear (); setmins (); lcd.clear(); RTC.adjust(DateTime(setyeartemp,setmonthtemp,setdaytemp,sethourstemp,setminstemp,setsecs)); CalcSun (); delay (1000); } // subroutine to return the length of the button push. int getpushlength () { buttonstate = digitalRead(A0); if(buttonstate == LOW && buttonflag==false) { pushstart = millis(); buttonflag = true; }; if (buttonstate == HIGH && buttonflag==true) { pushstop = millis (); pushlength = pushstop - pushstart; buttonflag = false; }; return pushlength; } // The following subroutines set the individual clock parameters int setyear () { lcd.setCursor (0,0); lcd.print ("Set Year"); pushlength = pushlengthset; pushlength = getpushlength (); if (pushlength != pushlengthset) { return setyeartemp; } lcd.setCursor (0,1); knob.write(0); delay (50); knobval=knob.read(); if (knobval < -1) { //bit of software de-bounce knobval = -1; } if (knobval > 1) { knobval = 1; } setyeartemp=setyeartemp + knobval; if (setyeartemp < 2014) { //Year can't be older than currently, it's not a time machine. setyeartemp = 2014; } lcd.print (setyeartemp); lcd.print(" "); setyear(); } int setmonth () { lcd.setCursor (0,0); lcd.print ("Set Month"); pushlength = pushlengthset; pushlength = getpushlength (); if (pushlength != pushlengthset) { return setmonthtemp; } lcd.setCursor (0,1); knob.write(0); delay (50); knobval=knob.read(); if (knobval < -1) { knobval = -1; } if (knobval > 1) { knobval = 1; } setmonthtemp=setmonthtemp + knobval; if (setmonthtemp < 1) {// month must be between 1 and 12 setmonthtemp = 1; } if (setmonthtemp > 12) { setmonthtemp=12; } lcd.print (setmonthtemp); lcd.print(" "); setmonth(); } int setday () { if (setmonthtemp == 4 || setmonthtemp == 5 || setmonthtemp == 9 || setmonthtemp == 11) { //30 days hath September, April June and November maxday = 30; } else { maxday = 31; //... all the others have 31 } if (setmonthtemp ==2 && setyeartemp % 4 ==0) { //... Except February alone, and that has 28 days clear, and 29 in a leap year. maxday = 29; } if (setmonthtemp ==2 && setyeartemp % 4 !=0) { maxday = 28; } lcd.setCursor (0,0); lcd.print ("Set Day"); pushlength = pushlengthset; pushlength = getpushlength (); if (pushlength != pushlengthset) { return setdaytemp; } lcd.setCursor (0,1); knob.write(0); delay (50); knobval=knob.read(); if (knobval < -1) { knobval = -1; } if (knobval > 1) { knobval = 1; } setdaytemp=setdaytemp+ knobval; if (setdaytemp < 1) { setdaytemp = 1; } if (setdaytemp > maxday) { setdaytemp = maxday; } lcd.print (setdaytemp); lcd.print(" "); setday(); } int sethours () { lcd.setCursor (0,0); lcd.print ("Set Hours"); pushlength = pushlengthset; pushlength = getpushlength (); if (pushlength != pushlengthset) { return sethourstemp; } lcd.setCursor (0,1); knob.write(0); delay (50); knobval=knob.read(); if (knobval < -1) { knobval = -1; } if (knobval > 1) { knobval = 1; } sethourstemp=sethourstemp + knobval; if (sethourstemp < 1) { sethourstemp = 1; } if (sethourstemp > 23) { sethourstemp=23; } lcd.print (sethourstemp); lcd.print(" "); sethours(); } int setmins () { lcd.setCursor (0,0); lcd.print ("Set Mins"); pushlength = pushlengthset; pushlength = getpushlength (); if (pushlength != pushlengthset) { return setminstemp; } lcd.setCursor (0,1); knob.write(0); delay (50); knobval=knob.read(); if (knobval < -1) { knobval = -1; } if (knobval > 1) { knobval = 1; } setminstemp=setminstemp + knobval; if (setminstemp < 0) { setminstemp = 0; } if (setminstemp > 59) { setminstemp=59; } lcd.print (setminstemp); lcd.print(" "); setmins(); } int setmode () { //Sets the mode of the timer. Auto, On or Off lcd.setCursor (0,0); lcd.print ("Set Mode"); pushlength = pushlengthset; pushlength = getpushlength (); if (pushlength != pushlengthset) { return TimerMode; } lcd.setCursor (0,1); knob.write(0); delay (50); knobval=knob.read(); if (knobval < -1) { knobval = -1; } if (knobval > 1) { knobval = 1; } TimerMode=TimerMode + knobval; if (TimerMode < 0) { TimerMode = 0; } if (TimerMode > 2) { TimerMode=2; } if (TimerMode == 0) { lcd.print("Off"); lcd.print(" "); } if (TimerMode == 1) { lcd.print("On"); lcd.print(" "); } if (TimerMode == 2) { lcd.print("Auto"); lcd.print(" "); } setmode (); } int CalcSun () { //Calculates the Sunrise and Sunset times DateTime now = RTC.now(); sunTime[3] = now.day(); // Give Timelord the current date sunTime[4] = now.month(); sunTime[5] = now.year(); myLord.SunRise(sunTime); // Computes Sun Rise. Sunrise = sunTime[2] * 60 + sunTime[1]; // Sunrise returned in minutes past midnight SunriseHour = sunTime[2]; SunriseMin = sunTime [1]; sunTime[3] = now.day(); // Uses the Time library to give Timelord the current date sunTime[4] = now.month(); sunTime[5] = now.year(); myLord.SunSet(sunTime); // Computes Sun Set. Sunset = sunTime[2] * 60 + sunTime[1]; // Sunset returned in minutes past midnight SunsetHour = sunTime[2]; SunsetMin = sunTime [1]; } void ShortPush () { //This displays the calculated sunrise and sunset times when the knob is pushed for a short time. for (long Counter = 0; Counter < 604 ; Counter ++) { //returns to the main loop if it's been run 604 times //(don't ask me why I've set 604,it seemed like a good number) lcd.setCursor (0,0); lcd.print ("Sunrise "); lcd.print (SunriseHour); lcd.print (":"); if (SunriseMin <10) { lcd.print("0"); } lcd.print (SunriseMin); lcd.setCursor (0,1); lcd.print ("Sunset "); lcd.print (SunsetHour); lcd.print (":"); if (SunsetMin <10) { lcd.print("0"); } lcd.print (SunsetMin); //If the knob is pushed again, enter the mode set menu pushlength = pushlengthset; pushlength = getpushlength (); if (pushlength != pushlengthset) { lcd.clear (); TimerMode = setmode (); } } }
To add the object in array in for loop we have several methods:first we can have to simply add those objects to the array then we can add them using for loop in array..... **in example:**we have a simple object *object that we added 3 times at diffrent index postion in array(**mutarray)..**and other method is to add the object from another array:for that we accessed the each object at current index from the array and added that to the another array(**mymutablearray**)... nsmutablearray *mutarray=[[nsmutablearray alloc]init]; for(int i=0;i<=2;i++) { nsstring *object=@"hello"; [mutarray addobject:object]; } nslog(@"mutable array==%@",mutarray); //if the object are in other array then nsarray *objarray=[[nsarray alloc]initwithobjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil]; nslog(@"obje==%@",objarray); nsmutablearray *mymutablearray=[[nsmutablearray alloc]init];; for(int index=0;index