spuddo Posted July 18, 2020 Report Share Posted July 18, 2020 Hi , can anyone assist with with a link to the code for the above. I watched the you tube , but the link provided for the schematic and code did not work. the link provided was http://goo.gl/2kqgVT Thanks Quote Link to comment Share on other sites More sharing options...
HarryA Posted July 18, 2020 Report Share Posted July 18, 2020 Given what he shows in the video one can emulate the code easily. If that is what you would like. Quote Link to comment Share on other sites More sharing options...
spuddo Posted July 19, 2020 Author Report Share Posted July 19, 2020 Hi HarryA , thanks for your reply. I am new to programming. I did copy what I saw from the video. Uploaded it and it did not work as described. It looked like a few lines of code were missing. Any thoughts? Best regards. Quote Link to comment Share on other sites More sharing options...
admin Posted July 20, 2020 Report Share Posted July 20, 2020 Could you point us to the original video? Have you tried to contact the author of it ? Quote Link to comment Share on other sites More sharing options...
HarryA Posted July 20, 2020 Report Share Posted July 20, 2020 The URL is: https://www.youtube.com/watch?v=bIz9ektLunE Following the link from youtube does not lead to anything useful. The code has numinous errors. It would never run, for spuddo: This is a snapshot of the serial monitor displaying the output of the code below. This is the circuit that I used. The duty control on the left. The two resistors limit the range of the output. You do not want zero duty cycle for example. The period control on the right. The resistor limits the period from going to zero for example. The code: // // A rework of the code from the video: https://www.youtube.com/watch?v=bIz9ektLunE // void virtual_Scope(); int iDutyCyclePin = 2; //set input pin for the left pot = duty cycle int iPeriodPin = 1; //set input pin for the right pot = peroid int iLedPin = 13; //ser pin for output to LED //float fFrequency; //frequency = how many full periods per second or per 1000 millisedonds float fPeriod = 10; //value from the left pot float fDuty = 1; long int liPeriod, liDuty; int iDutyPercent; long int liHigh_Time, liLow_Time; void setup() { pinMode(iLedPin, OUTPUT); //declare ledpin as OUTPIN //Serial Port begin Serial.begin (9600); } void loop() { fPeriod = analogRead(iPeriodPin); //read the value from the right pot = period fDuty = analogRead(iDutyCyclePin); //read the value from the left pot = duty cycle //limit the range of the duty cycle to 20 to 80 percent of the period because that is what works! fDuty = (fDuty*9/10000) * fPeriod ; //with 5 volt supply liDuty = int(fDuty); //for printouts below liPeriod = int(fPeriod); //iDutyPercent = 100*liDuty/1024; //cal duty cycle as percent for serial monitor ???? iDutyPercent = 100*liDuty/liPeriod; //cal duty cycle as percent for serial monitor // fFrequency = (1000/float(liPeriod)); //cal frequency in units of Hertz for serial monitor ??? // liHigh_Time = liDuty*liPeriod/1024; //cal high = on time ??? liHigh_Time = liDuty; // high = on time liLow_Time = liPeriod - liHigh_Time; //cal low = off time Serial.println(); //new line Serial.print("period "); Serial.print(liPeriod); Serial.println(" milliseconds"); Serial.print("duty "); Serial.print(liDuty); Serial.println(" milliseconds"); Serial.print("on time "); Serial.print(liHigh_Time); Serial.println(" milliseconds"); Serial.print("off time "); Serial.print(liLow_Time); Serial.println(" milliseconds"); Serial.print(" duty cycle "); Serial.print(iDutyPercent); Serial.println(" % "); // Serial.print("frequency "); //what is frequency here? // Serial.print(fFrequency); // Serial.println(" Hertz"); digitalWrite(iLedPin, HIGH); //set the ledPin on delay(liHigh_Time); //pause the program for high_time in microseconds digitalWrite(iLedPin, LOW); //set the ledPin off delay(liLow_Time); //pause the program for low_time in microseconds virtual_Scope(); //display trace delay(4000); //slow down the scrolling } void virtual_Scope() { //display a line of pulses int iHighDashes, iLowDashes; int iCount; //let one dash = 30 ms iHighDashes = liHigh_Time/30; iLowDashes = liLow_Time/30; iCount = 60/(iHighDashes+iLowDashes); //try to make the lengths similar // Serial.println(String(iCount) + " "+ String(iLowDashes) + " " + String(iHighDashes) ); //new line for space at top Serial.println(); //space at top while (iCount--) { for (int i=0; i <iLowDashes; i++) { Serial.print("_"); } for (int i=0; i <iHighDashes; i++) { Serial.print("-"); } } Serial.println(); //space at bottom } Quote Link to comment Share on other sites More sharing options...
spuddo Posted July 22, 2020 Author Report Share Posted July 22, 2020 Hi. Thanks for your reply HarryA. That program needed some surgery. Ran yours and it achieved its aims. I am needing a audio version , say five octaves that allows freq and duty cycle to vary independently. Any thoughts. Best regards. Quote Link to comment Share on other sites More sharing options...
HarryA Posted July 22, 2020 Report Share Posted July 22, 2020 If you search for Arduino function or signal generator you will find some useful information. Like: https://circuitdigest.com/microcontroller-projects/arduino-waveform-generator Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.