H-bridge: an integrated circuit that has many transistors inside to reverse the polarity.
int pin1 = 7; int pin2 = 8; void setup(){ pinMode(pin1, OUTPUT); pinMode(pin2, OUTPUT); } void loop() { for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(pin1, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(pin2, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(pin2, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(pin1, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } }
int int pin1 = 7; int pin2 = 8; void setup(){ pinMode(pin1, OUTPUT); pinMode(pin2, OUTPUT); } void loop() { digitalWrite(pin1, HIGH); digitalWrite(pin2, LOW); delay(5000); digitalWrite(pin1, LOW); digitalWrite(pin2, HIGH); delay(5000); }
Leave a Reply