Page 1 of 1

d13 led is not pin 17! i am confused :^)

Posted: Tue Sep 15, 2015 10:06 am
by haveachillday
according to the usb droid schematic, pin 17 on the micro controller is the on board led and also digital plug 13. this is confusing me because i tested the blink sketch with pin 17 and it would not flash. however, testing:

dIgitalWrite(13,HIGH); // this lights up the led! strange no?

on top of all that, my custom code here will output to serial console in the IDE (line 39) but wont output to the led on pin 13!

i am very confused by this on board led: how it works with the blink code but not with my code. if there are any wizards out there who can weigh in i seem to have hit a rut in my education. :^(

*EDIT* i think its possible that d13 led is prioritised for SD card clock (SCK) which i am attempting to use in my code. you can see this by looking at the sd card slot on the droid schematic.

Code: Select all

#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h>
#include <SPI.h>            //due to a problem with the SD library, research suggest this must be included to access that library.
#define SD_ChipSelectPin 2  //we use this as a sensor to detect if sd card is present.
TMRpcm tmrpcm;              //creates an object pointing at the TMRpcm library for use in this sketch.
bool loopnumber = false;
float final = 0.0;
float initial = 0.0;
float vchange = 0.0;

void setup(){
  Serial.begin(9600); // allows communication with the computer at 9600 bits/S.
  if (!SD.begin(SD_ChipSelectPin)) {
    Serial.println("Can't detect sd card.");  //check the sd card is working.
  }
  else {
    Serial.println("Ready for action!");
  }
  tmrpcm.speakerPin = 28;
  pinMode(13,OUTPUT);    // led d13.
  pinMode(24,INPUT);     //pin A1.
  pinMode(25,INPUT);     //pin A2.
  pinMode(26,INPUT);     //pin A3.
  pinMode(27,INPUT);     //pin A4.
  pinMode(28,OUTPUT);    //pin A5 is the analogue audio output. analogue pins work as digital outputs.
}

void loop() {
  float pinA4 = analogRead(27) * (5.0 / 1023.0);
  if (!loopnumber) {
    initial = pinA4;
    loopnumber = true;  
  }
    final = pinA4;
    vchange = final - initial;
    if (vchange >= 0.3) {
      Serial.println("Button pressed. ");						//LINE 39
      tmrpcm.play("sound1.wav");   
      digitalWrite(13,HIGH);								//NOT LIGHTING UP!
      //delay(5000); //5 second/s before any other high level code is processed.  
    }
  //Serial.println("loopnumber: " + (String)loopnumber + " \ pinA4 = " + (String)pinA4 + " \ vchange = " + (String)vchange);
  initial = final;
}

Re: d13 led is not pin 17! i am confused :^)

Posted: Tue Sep 15, 2015 10:53 pm
by andrew
When you consider the schematic, pin 17 is the physical pin number of the microcontroller itself ... which then goes to the Arduino Uno position D13.

Re: d13 led is not pin 17! i am confused :^)

Posted: Tue Sep 15, 2015 11:02 pm
by haveachillday
hi john i was under the impression that to program pins on the Arduino IDE, I would have to use the microcontroller pins and not there plug names. am I mistaken? how then would we differentiate between d5 and a5?

Re: d13 led is not pin 17! i am confused :^)

Posted: Tue Sep 15, 2015 11:12 pm
by andrew
When using the Arduino IDE software you use the Arduino's abstract pin numbers.
D5 and A5 are differentiated by the D and A.

Easy reference below ... analogue pins are A0~A5 on the left, digital are D0~D13 on the right. USBDroid also has A6 and A7 between the microcontroller and the uSD card socket.

Image

Re: d13 led is not pin 17! i am confused :^)

Posted: Tue Sep 15, 2015 11:18 pm
by haveachillday
yeah that infographic clears everything up! thank you sir madam :D

Re: d13 led is not pin 17! i am confused :^)

Posted: Fri Apr 21, 2017 8:51 am
by cadmodeling777
thanks for this information.