On an arduino nano after configuring the pin mode and setting D4 pin to high, as per LED example, I can't seem to get the digital output to go High. There is no level change.
Post your code.
...R
Here's the code
#include <SoftwareSerial.h>
const int InputFrequency = 5000;
const int OutputFrequency = 1024;
volatile int PulseCount = 0;
volatile float Divisor = (((float)InputFrequency) / ((float)OutputFrequency));
volatile float NextOutputPulse = Divisor;
volatile boolean TriggerPulse = true;
const int ExtInterruptNumber = 0; // external interrupt number for D2 input - signal from encoder to Nano
const int EIn = 5; // D2 is encoder input: pin #5
const int EOut = 7; // D4 is reduced encoder ouput: pin #7
void setup() {
// setup code
Serial.begin (9600);
/* Serial.print ("Divisor: ");
Serial.print (Divisor);
Serial.print (" NextOutput Pulse: ");
Serial.print (NextOutputPulse);
Serial.println (" interrupts enabled!");
*/
pinMode(EIn, INPUT);
pinMode(EOut, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
//attachInterrupt(ExtInterruptNumber, PulseGenerator, RISING); // interrupt on rising edge of signal
//interrupts();
}
void PulseGenerator() { // ISR
++PulseCount;
// check to see if it is time to ouput a pulse
if (PulseCount == ((int)((float)(NextOutputPulse+0.5))))
{
// Reset the pulse counters to zero to limit the maximize number value
// to that of the input frequency. This will prevent the counter from getting
// larger than the allowable max integer value
if ((int)NextOutputPulse >= InputFrequency)
{
PulseCount = 0;
NextOutputPulse = 0;
}
SendOutputPulse();
NextOutputPulse += Divisor;
}
}
void loop(){
// main program loop
// no action required
// everything is done in ISR
Serial.print ("H");
digitalWrite(EOut, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
delay (500);
digitalWrite(EOut, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
Serial.print ("L ");
delay(500);
}
void SendOutputPulse() {
Serial.print("P ");
digitalWrite(EOut, HIGH);
// may need a delay in here to ensure pulse width is sufficient
// but this is in the ISR - BE CAREFUL
unsigned int i;
for(i=0; i<60000; i++);
digitalWrite(EOut, LOW);
Serial.println(".");
}
Here's the code
There is no mention of pin 4 anywhere in that code.
You've commented out the call to attachInterrupt(). You should have, since it and the related variables and functions are not related to the problem, deleted that crap.
It was actually output D4 - Pin 7. The other output commands were to see if I could get any other pins to go high.
Please use the code button </> to make your code look like this
so it is easy to select and copy to a text editor.
I have tried three times to select what you have posted and each time it has screwed up. I won't try again.
...R
And the LED on pin 12 is flashing, right?
@cbertoni: Please edit your post, select the code, and put it between [code] ... [/code] tags.
You can do that by hitting the "Code" icon above the posting area. It is the first icon, with the symbol: </>
Can you please post a Minimal, Complete, and Verifiable example ? Saying you can't turn on pin 4, when pin 4 is not mentioned, is not helpful.
unsigned int i;
for(i=0; i<60000; i++);
The compiler will optimize that loop entirely away.
//attachInterrupt(ExtInterruptNumber, PulseGenerator, RISING); // interrupt on rising edge of signal
...
void PulseGenerator() { // ISR
...
SendOutputPulse();
}
...
void SendOutputPulse() {
Serial.print("P ");
...
Serial.println(".");
}
Assuming you enable that interrupt one day: Don't do serial prints inside an ISR.
#include <iostream>
/* A comment */
// Another comment
int main()
{
std::cout << "Hello, world!\n";
int foo = 42;
return 0;
}