Messing With Arduino Simulator

by Alan_Hanrahan in Circuits > Arduino

470 Views, 0 Favorites, 0 Comments

Messing With Arduino Simulator

This is limerick Citay1.PNG

Circuits.io woo!

Detecting the Button Presses

ar1.PNG
ar2.PNG

Make a circuit to detect when a button is pressed. You can view this in the Serial monitor in the Circuits.io webtool. This is the code:

const int buttonPin = 2;

int buttonState;

void setup() {

pinMode(buttonPin, INPUT);

Serial.begin(9600);

}

void loop() {

buttonState = digitalRead(buttonPin);

Serial.println(buttonState);

delay(100);

}

Mess Around With the Circuit.

ar3.PNG
ar4.PNG

Same code, but change the circuit around to see what happens. Answer: Nothing.

Dimming an LED

ar5.PNG

wire it up to dim the LED using analogue output, PWM, which stands for Pulse Width Modulation.

CODE:

int led = 9; // the PWM pin the LED is attached to

int brightness = 0; // how bright the LED is

int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:

void setup() {

// declare pin 9 to be an output:

pinMode(led, OUTPUT);

}

// the loop routine runs over and over again forever:

void loop() {

// set the brightness of pin 9:

analogWrite(led, brightness);

// change the brightness for next time through the loop:

brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:

if (brightness == 0 || brightness == 255) {

fadeAmount = -fadeAmount ;

}

// wait for 30 milliseconds to see the dimming effect

delay(30);

}

I could not get anything to happen.

Servo Motor!

ar6.PNG

Getting motion to happen with the arduino.

CODE:

#include

Servo myservo; // create servo object to control a servo

// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {

myservo.attach(9); // attaches the servo on pin 9 to the servo object

}

void loop() {

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180

degrees

// in steps of 1 degree

myservo.write(pos); // tell servo to go to position in

variable 'pos'

delay(15); // waits 15ms for the servo to reach

the position

}

for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0

degrees

myservo.write(pos); // tell servo to go to position in

variable 'pos'

delay(15); // waits 15ms for the servo to reach

the position

}

}