User Tools

Site Tools


digispark:tutorials:basics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
digispark:tutorials:basics [2013/03/29 06:48]
PeterMortensen [Analog Read:] Copy edited [5]. Replaced TABs with space to ease formatting.
digispark:tutorials:basics [2016/06/09 12:03] (current)
Line 26: Line 26:
     digitalWrite(0,​HIGH);​ //Turn the pin HIGH (5 V)     digitalWrite(0,​HIGH);​ //Turn the pin HIGH (5 V)
     delay(1000);​     delay(1000);​
-    digitalWrite(0,​HIGH); //Turn the pin LOW (GND)+    digitalWrite(0,​LOW); //Turn the pin LOW (GND)
     delay(1000);​     delay(1000);​
 } }
Line 71: Line 71:
     //​sensorValue = analogRead(2);​ //Read P4     //​sensorValue = analogRead(2);​ //Read P4
     //To set to input: pinMode(4, INPUT);     //To set to input: pinMode(4, INPUT);
-    //THIS IS P4, P2 is analog input 2, so when you are using analog read, you refer to it as 2.+    //THIS IS P4, P4 is analog input 2, so when you are using analog read, you refer to it as 2.
  
     //​sensorValue = analogRead(3);​ //Read P3     //​sensorValue = analogRead(3);​ //Read P3
Line 83: Line 83:
 </​code>​ </​code>​
  
-===== Analog Write: (aka PWM)=====+===== Analog Write: (AKA PWM)=====
 <​code>​ <​code>​
 void setup() { void setup() {
-  ​//P0, P1, and P4 are capable of hardware PWM (analogWrite) +    ​//P0, P1, and P4 are capable of hardware PWM (analogWrite). 
-  pinMode(0, OUTPUT); //0 is P0, 1 is P1, 4 is P4 - unlike the analog inputs, for analog (PWM) outputs the pin number matches+    pinMode(0, OUTPUT); //0 is P0, 1 is P1, 4 is P4 - unlike the analog inputs, ​ 
 +                        //for analog (PWM) outputs the pin number matches ​the port number.
 } }
  
 void loop() { void loop() {
- analogWrite(0,​255);​ //turn the pin on full (100%) +    ​analogWrite(0,​255);​ //Turn the pin on full (100%) 
- delay(1000);​ +    delay(1000);​ 
- analogWrite(0,​128);​ //turn the pin on half (50%) +    analogWrite(0,​128);​ //Turn the pin on half (50%) 
- delay(1000);​ +    delay(1000);​ 
- analogWrite(0,​0);​ //turn the pin off (0%) +    analogWrite(0,​0); ​  ​//Turn the pin off (0%) 
- delay(1000);​+    delay(1000);​
 } }
 </​code>​ </​code>​
 +
digispark/tutorials/basics.1364564886.txt.gz · Last modified: 2013/03/29 06:48 by PeterMortensen